sql grouping with rollup 按部门 合并一些部门
16lz
2021-01-22
分类汇总
----------------------------------------------------------------
select CASE WHEN GROUPING([DEP])=1 THEN '总计' ELSE [DEP] END as DEP,
isnull(sum(CASE WHEN [Date] between '2013-01-1' and '2013-12-31' THEN [加班时间] END),0.0) as january
from [KQ] where [KQ].company='北京公司' Group by DEP WITH ROLLUP
合并部门:现场A部门->到A部门
----------------------------------------------------------------
select CASE WHEN GROUPING([DEP])=1 THEN '总计' ELSE replace([DEP],'现场','') END as DEP,
isnull(sum(CASE WHEN [Date] between '2013-01-1' and '2013-12-31' THEN [加班时间] END),0.0) as january
from [KQ] where [KQ].company='北京公司' Group by DEP WITH ROLLUP