Closed. This question needs details or clarity . It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post .
Closed 5 hours ago.
Improve this question
I am new to SQL Server. I have a table with columns Region
, State
and Sales
- like this:
Region | State | Sales |
---|---|---|
East | California | 100 |
East | texas | 200 |
West | roseland | 100 |
West | Newjerea | 200 |
I need to show region-wise sales along with state-wise sales in the same query.
Could any one please help how to do this?
1条答案
按热度按时间g2ieeal71#
You can use rollup with group by clause like below to get region wise, state wise and total sales summary:
Query:
Output:
fiddle
Or you can use window function sum()over() to get the region-wise sales like below:
Query:
Output:
fiddle