Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Use Different Group By and Order By Columns with Sub-query

$
0
0
I'm trying to only display certain columns and order by different columns from an aggregate group by query using a grouping set. To do this I'm using a sub-query.I have two questions:1. Is there a better way to group by and order by diff columns?2. Are there performance problems with using sub-query this way?Query:[code="sql"]SELECT Region, State, Sales FROM ( SELECT RegionID, Region, StateID, State, SUM(Sales) AS Sales FROM Sales GROUP BY GROUPING SETS( (RegionId, Region, StateID, State), (StateId, State), () ) ) As T1 ORDER BY RegionID, StateID[/code]

Viewing all articles
Browse latest Browse all 3145

Trending Articles