674,582 questions
-3
votes
0
answers
41
views
SQL subquery issue [closed]
enter image description here (SQL subquery problem)
enter image description here (SQL subquery problem)
See the same result came without using the subquery. So why should I use this complicated ...
Best practices
1
vote
1
replies
29
views
How do I design an ERD and SQL schema for a basic banking system (accounts & transactions)?
I'm working on a small educational project: building a simple banking system that includes customers, accounts, and transactions.
I have read about ERD modeling but I'm not sure how to properly ...
0
votes
1
answer
46
views
Trigger on PostgreSQL updating salary column
I am having some troubles setting a trigger in PostgreSQL. I have a table Employees with columns such as employee_id, salary and hourly_pay. The salary is annual, so I'd like to change the salary when ...
-2
votes
0
answers
58
views
How can I join two tables on different columns? [duplicate]
I have two tables; the first one consists of clients' names and their id.
For example:
name surname1 519651
name surname2 496879
name surname3 848465
The second one consists of clients'...
-1
votes
1
answer
70
views
Showing exclusively the biggest value [duplicate]
I've been tasked with finding the client with the highest sum of payments, the table they gave me contains the customer number and amount, I have not been able to do this,
SELECT suma.customerNumber, ...
-4
votes
1
answer
82
views
How to insert every combination of two tables as two columns in another table [duplicate]
Let's say I have table A and table B
table A has one column A, comprised of 4 values
A
1
2
3
4
table B also has one column, called B, comprised of 13 values
B
1
2
3
4
5
6
7
8
9
10
11
12
13
Now, ...
0
votes
0
answers
110
views
How to use index in simple select
Table has index on name column:
CREATE TABLE firma2.klient
(
kood character(12) primary key,
nimi character(100),
...
);
CREATE INDEX IF NOT EXISTS ...
1
vote
2
answers
102
views
How to call Postgres function from .NET? [closed]
I tried this code:
CREATE OR REPLACE FUNCTION public.t4(in iid int, OUT n1 text, OUT n2 text)
LANGUAGE plpgsql
AS $function$
BEGIN
SELECT DISTINCT n1=l.name, n2=l.comment from ...
Best practices
0
votes
7
replies
94
views
MySQL SELECT … FOR UPDATE causing table lock during high traffic while generating sequential transaction IDs
I have a PHP + MySQL project where I need to generate sequential transaction IDs.
Each transaction can have multiple items, so all rows for that transaction must share the same txn_in value.
Tables
...
Advice
0
votes
2
replies
60
views
How split hash-join in Trino into more parts?
I have a query with join. When Trino has 10 workers it works. When 5 - it fails. As I understand the situation (Trino call this DistributedHashJoon) - it splits entire table into 10 pieces, so smaller ...
-4
votes
1
answer
80
views
Aggregate rows from another table to the select of one table [closed]
Let's say I have a table named People with a column PeopleID. I have another table Payment. Each row in this table has 3 columns:
PeopleId, Amount, Date
The date is always the fist day of the month. ...
1
vote
2
answers
101
views
Convert the string date type into date type while creating a table
I am trying to convert the string date type that retrieved from a column.
Below is the scenario
#input
date_str
02/08/24
21/09/2023
25.02.16
null
null
I need to convert above column into a new ...
-2
votes
1
answer
70
views
What is the correct syntax for using the Lead Function in SQL Anywhere [closed]
Handbook:
LEAD (value_expr) [, offset [, default]]) OVER ([PARTITION BY window partition] ORDER BY window ordering)
This could not be right.
My code looks like that:
SELECT
LEAD(tbl6.StartTime, 1, ...
0
votes
2
answers
154
views
How to pivot rows into a concatenated column [duplicate]
I have a query that outputs the below result:
users
file_consumed
John
orders
Martin
orders
Alice
orders
Bob
payments
Alex
payments
Julie
payments
John
deliveries
Bob
deliveries
I want to convert this ...
0
votes
2
answers
127
views
Parse JSON object in SQL with list
I have a table with data structured like this. Each product ID has a list of element IDs--for each element, there is a dictionary including a list of elements and their assigned IDs. Not every element ...