Currently I have a table like this:
| Partno | Total |
| ------------ | ------------ |
| 0100 | 50 |
| 0100 | 200 |
| 0100 | 300 |
| 0450 | 100 |
| 0450 | 350 |
| 0600 | 250 |
I'd like to get a result like this:
Partno | Total |
---|---|
0100 | 550 |
0100 | 50 |
0100 | 200 |
0100 | 300 |
0450 | 450 |
0450 | 100 |
0450 | 350 |
0600 | 250 |
0600 | 250 |
Where the italic rows are grouped-by on Partno. How can I get this result using a query?
Right now I have to do it using a master-detail grid, because I can't fit it in 1 query.
3条答案
按热度按时间g2ieeal71#
This will retrieves all rows from the table and also includes additional rows that represent the sum of Total values for each unique Partno :
Demo here
z3yyvxxp2#
Seems like you need to use
GROUPING SETS
here. Note that if you have 2 or more rows with the same value ofTotal
they will be aggregated; if that's the case you should be using your primary key column instead (which is omitted in the sample data):h9a6wy2h3#
You can achieve it by using UNION ALL between two queries: