日期:2014-05-17  浏览次数:20608 次

求一个按月份(季度)合计的sql语句
本帖最后由 u010248119 于 2013-11-21 12:43:14 编辑
要求查询结果如下面的格式,求一个sql语句

时   间

2013年1月
2013年2月
2013年3月
一季度汇总
2013年4月
2013年5月
2013年6月
二季度汇总
2013年7月
2013年8月
2013年9月
三季度汇总
2013年10月
2013年11月
2013年12月
四季度汇总
2013年汇总
sql?server

------解决方案--------------------
类似这样的代码:



select XX from tb group by XX  --明细

union all

select case when XX = 1 then '一季度汇总' 
            when xx = 2 then ...
from tb group by 季度

union all

select sum()
from tb   --全年汇总

------解决方案--------------------
group by rollup来汇总