Newbie needs help on query (MYSQL)
up vote
0
down vote
favorite
I'm new here and nearly new in SQL.
My problem:
I've a table (T1) with
Datetime, CostNo, Amount
second table (T2) with
Date, CostNo, BillNo
In the query should be
Date, CostNo, BillNo, Amount
My problem are several BillNos for the same CostNo the same day.
I need a kind of sorting the BillNo according to the Datetime.
T1 f.e.:
2018-11-02 11:14:52 3637 24.10
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00
T2 f.e.:
2018-11-02 3637 26189
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196
so my query:
select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate
works fine until CostNo 2552:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
This should be the result:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
mysql sql
|
show 3 more comments
up vote
0
down vote
favorite
I'm new here and nearly new in SQL.
My problem:
I've a table (T1) with
Datetime, CostNo, Amount
second table (T2) with
Date, CostNo, BillNo
In the query should be
Date, CostNo, BillNo, Amount
My problem are several BillNos for the same CostNo the same day.
I need a kind of sorting the BillNo according to the Datetime.
T1 f.e.:
2018-11-02 11:14:52 3637 24.10
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00
T2 f.e.:
2018-11-02 3637 26189
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196
so my query:
select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate
works fine until CostNo 2552:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
This should be the result:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
mysql sql
3
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
4
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new here and nearly new in SQL.
My problem:
I've a table (T1) with
Datetime, CostNo, Amount
second table (T2) with
Date, CostNo, BillNo
In the query should be
Date, CostNo, BillNo, Amount
My problem are several BillNos for the same CostNo the same day.
I need a kind of sorting the BillNo according to the Datetime.
T1 f.e.:
2018-11-02 11:14:52 3637 24.10
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00
T2 f.e.:
2018-11-02 3637 26189
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196
so my query:
select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate
works fine until CostNo 2552:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
This should be the result:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
mysql sql
I'm new here and nearly new in SQL.
My problem:
I've a table (T1) with
Datetime, CostNo, Amount
second table (T2) with
Date, CostNo, BillNo
In the query should be
Date, CostNo, BillNo, Amount
My problem are several BillNos for the same CostNo the same day.
I need a kind of sorting the BillNo according to the Datetime.
T1 f.e.:
2018-11-02 11:14:52 3637 24.10
2018-11-02 11:16:43 965 2.50
2018-11-02 11:40:28 2552 3.50
2018-11-02 11:40:51 2552 3.00
2018-11-02 11:41:10 2552 3.50
2018-11-02 11:41:36 2552 3.00
2018-11-02 11:55:03 980 3.00
2018-11-02 11:59:11 1976 3.00
T2 f.e.:
2018-11-02 3637 26189
2018-11-02 965 26190
2018-11-02 2552 26191
2018-11-02 2552 26192
2018-11-02 2552 26193
2018-11-02 2552 26194
2018-11-02 980 26195
2018-11-02 1976 26196
so my query:
select
T2.BillDate,
T2.CostNo,
T2.BillNo,
T1.Amount
from
`T2`,
`T1`
where
T1.CostNo =T2.CostNo
AND DATE(T1.BillDateTime) = T2.BillDate
works fine until CostNo 2552:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26191 3.50
2018-11-02 2552 26191 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26192 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26193 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 2552 26194 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
This should be the result:
2018-11-02 3637 26189 24.10
2018-11-02 965 26190 2.50
2018-11-02 2552 26191 3.50
2018-11-02 2552 26192 3.00
2018-11-02 2552 26193 3.50
2018-11-02 2552 26194 3.00
2018-11-02 980 26195 3.00
2018-11-02 1976 26196 3.00
mysql sql
mysql sql
edited Nov 22 at 7:17
asked Nov 21 at 9:30
Schnurze
11
11
3
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
4
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33
|
show 3 more comments
3
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
4
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33
3
3
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
4
4
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33
|
show 3 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
I am guessing that you want:
select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;
First note the proper use of JOIN
. Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax.
Second, if you want the results in a particular order, then your query should have an ORDER BY
clause. SQL tables and result sets (with no ORDER BY
) represent unordered sets. So, you need an ORDER BY
. I am guessing you want to keep all the CostNo
s together, and then within each, ordered by the date/time.
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
add a comment |
up vote
0
down vote
OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.
Feel free to post a better and/or shorter solution.
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I am guessing that you want:
select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;
First note the proper use of JOIN
. Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax.
Second, if you want the results in a particular order, then your query should have an ORDER BY
clause. SQL tables and result sets (with no ORDER BY
) represent unordered sets. So, you need an ORDER BY
. I am guessing you want to keep all the CostNo
s together, and then within each, ordered by the date/time.
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
add a comment |
up vote
1
down vote
I am guessing that you want:
select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;
First note the proper use of JOIN
. Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax.
Second, if you want the results in a particular order, then your query should have an ORDER BY
clause. SQL tables and result sets (with no ORDER BY
) represent unordered sets. So, you need an ORDER BY
. I am guessing you want to keep all the CostNo
s together, and then within each, ordered by the date/time.
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
add a comment |
up vote
1
down vote
up vote
1
down vote
I am guessing that you want:
select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;
First note the proper use of JOIN
. Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax.
Second, if you want the results in a particular order, then your query should have an ORDER BY
clause. SQL tables and result sets (with no ORDER BY
) represent unordered sets. So, you need an ORDER BY
. I am guessing you want to keep all the CostNo
s together, and then within each, ordered by the date/time.
I am guessing that you want:
select T2.BillDate, T2.CostNo, T2.BillNo, T1.Amount
from `T2` join
`T1`
on T1.CostNo = T2.CostNo and DATE(T1.BillDateTime) = T2.BillDate
order by T!.CostNo, T1.BillDateTime DESC;
First note the proper use of JOIN
. Never use commas in the FROM
clause. Always use proper, explicit, standard JOIN
syntax.
Second, if you want the results in a particular order, then your query should have an ORDER BY
clause. SQL tables and result sets (with no ORDER BY
) represent unordered sets. So, you need an ORDER BY
. I am guessing you want to keep all the CostNo
s together, and then within each, ordered by the date/time.
answered Nov 21 at 11:57
Gordon Linoff
747k34285390
747k34285390
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
add a comment |
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
OK, another code, looks good or even better then mine, but didn't solve the problem.
– Schnurze
Nov 22 at 7:22
add a comment |
up vote
0
down vote
OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.
Feel free to post a better and/or shorter solution.
New contributor
add a comment |
up vote
0
down vote
OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.
Feel free to post a better and/or shorter solution.
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.
Feel free to post a better and/or shorter solution.
New contributor
OK thanks for the help. I found a solution by myself.
Here it is, if someone will know it:
The BillNo from the 2. table is linked to the DateTime of table 1
So I build a temporaray table from table 1 with SUM/GROUP BY and ORDER BY on DateTime and add a row ID (auto_increment).
Next I build a temporary table from table 2, order by BillNo and add a row ID.
Now I can do a query with T1.ID = T2.ID and that's it.
Feel free to post a better and/or shorter solution.
New contributor
New contributor
answered Nov 23 at 11:20
Schnurze
11
11
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53408925%2fnewbie-needs-help-on-query-mysql%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Welcome to Stack Overflow! Please provide a relevant and minimal sample data showcasing your requirements, and expected output. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Madhur Bhaiya
Nov 21 at 9:30
4
Why are "amount" and "billno" in separate tables, yet related to the same costNo? Surely the amount relates to a specific bill? It's not clear whether the problem is in your data structure, or just your query. Please provide some sample data from each table, and also show the expected result of the query. Thanks.
– ADyson
Nov 21 at 9:33
Please review dev.mysql.com/doc/refman/8.0/en/group-by-functions.html and post your attempted query.
– P.Salmon
Nov 21 at 9:46
There is an example in this tutorial (orders>>orderdetails) mysqltutorial.org/mysql-group-by.aspx which looks similar to what you want.
– P.Salmon
Nov 21 at 10:05
Thanks for the update. But 1) what did you want it to output instead? And 2) Can you please answer my question from the comment above, so we can clarify the semantics of the data structure.
– ADyson
Nov 21 at 11:33