kk_nou kk_nou - 1 year ago 93
SQL Question

Raw data before each group by

Which queries should I execute in order to show raw data before every group by row? Is there a way to do that?

User ReceiptNo Price
----- ---------- ------
A 876 100
A 877 50
B 960 60
B 961 40

Answer Source

Most database support standard group by modifiers such as rollup or grouping sets. If so, you can do:

select user, receiptno, sum(price) as price
from t
group by grouping sets ((user, receiptno), (user));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download