求这个报表的写法上图中有大概的数据表和需要的报表格式 求大神能给出个sql本人对报表这块不熟悉 希望有大神帮助哈 再次谢过
Quote: 引用:对,就是这样:select '部门'+cast(部门 as varchar) as 部门, sum(case when 出行方式 = 1 then 总钱数 else 0 end) as 出行方式1, sum(case when 出行方式 = 2 then 总钱数 else 0 end) as 出行方式2, sum(case when 出行方式 = 3 then 总钱数 else 0 end) as 出行方式3, sum(case when 出行方式 = 4 then 总钱数 else 0 end) as 出行方式4, SUM(总钱数) as 总计 from 数据表 group by '部门'+cast(部门 as varchar)/*部门出行方式1出行方式2出行方式3出行方式4总计部门110020000300部门240000100500部门3001000100部门4300000300部门59001000190部门68000080*/ 大神 谢谢了 感谢 参加工作没多久 好多东西学的不好 呵呵
对,就是这样:select '部门'+cast(部门 as varchar) as 部门, sum(case when 出行方式 = 1 then 总钱数 else 0 end) as 出行方式1, sum(case when 出行方式 = 2 then 总钱数 else 0 end) as 出行方式2, sum(case when 出行方式 = 3 then 总钱数 else 0 end) as 出行方式3, sum(case when 出行方式 = 4 then 总钱数 else 0 end) as 出行方式4, SUM(总钱数) as 总计 from 数据表 group by '部门'+cast(部门 as varchar)/*部门出行方式1出行方式2出行方式3出行方式4总计部门110020000300部门240000100500部门3001000100部门4300000300部门59001000190部门68000080*/
select '部门'+cast(部门 as varchar) as 部门, sum(case when 出行方式 = 1 then 总钱数 else 0 end) as 出行方式1, sum(case when 出行方式 = 2 then 总钱数 else 0 end) as 出行方式2, sum(case when 出行方式 = 3 then 总钱数 else 0 end) as 出行方式3, sum(case when 出行方式 = 4 then 总钱数 else 0 end) as 出行方式4, SUM(总钱数) as 总计 from 数据表 group by '部门'+cast(部门 as varchar)/*部门出行方式1出行方式2出行方式3出行方式4总计部门110020000300部门240000100500部门3001000100部门4300000300部门59001000190部门68000080*/
from 数据表 group by '部门'+cast(部门 as varchar)/*部门出行方式1出行方式2出行方式3出行方式4总计部门110020000300部门240000100500部门3001000100部门4300000300部门59001000190部门68000080*/