sql語句: SELECT c1,c2,c3,c4,c5 FROM table GROUP by c1,c2,c3,c4,c5 WITH ROLLUP HAVING c1 IS NOT NULL ORDER BY c5,c4 這樣group 之後匯總的欄位都被order by到了後面, 如何才能保留rollup的樣子並且除了匯總的欄位都 按c5,c4排列。
--测试数据
declare @t table(a int,b int,c int)
insert @t select 1,9,10
union all select 1,8,10
union all select 1,7,10
union all select 2,6,10
union all select 2,5,10
union all select 2,4,10
union all select 3,1,10
union all select 3,2,10
union all select 3,3,10
--查询
select a,b,c=sum(c)
from @t
group by a,b with rollup
order by grouping(a),a --楼主看看不加排序与加排序的区别
,grouping(b),b desc