I want to get the sum of group A and group B respectively, and then divide by the sum.
I tried using this:
select name, sum(qt) from ntbl group by name
order_id | Name | qt |
---|---|---|
1 | one | 12 |
2 | one | 20 |
3 | B | 33 |
4 | B | 45 |
The result should be:
Name | qt | dv |
---|---|---|
one | 32 | 0.29 |
B | 78 | 0.70 |
You can cross-join another subquery that sums all quantities
dbviolinhere p>
You can combine aggregate functions and window functions together: