问题描述
- 添加合计行,求教sql问题
- select c.dept_namea.B_num as 本期
case when sum(b.T_num)=0 then 0 else sum(a.B_num)-sum(b.T_num) end 本期增加
from (
select count(PERSION_NAME) B_numdept_codeyearacct_month from BASE_PERSON
group by dept_codeyearacct_month
) a LEFT JOIN
(select count(PERSION_NAME) T_numdept_codeyearacct_month from BASE_PERSON
group by dept_codeyearacct_month
) b on a.dept_code=b.dept_code and a.year=b.year+1 and a.acct_month=b.acct_month
left join sys_dept c on a.dept_code=c.dept_code
where a.year='2014' and a.acct_month='01'
group by c.dept_namea.B_numb.T_numc.dept_code
ORDER BY c.dept_code
添加一行合计该怎么做呢?
解决方案
解决方案二:
能说清楚点吗?你的表结构列一下,你的临时表也列一下,然后说说你到底想合计个啥?你是要在滚动累计最后一行出合计么?是的话用过程累加一下就好了
解决方案三:
参看ROLLUP的用法
https://technet.microsoft.com/en-us/library/ms189305(v=sql.90).aspx
时间: 2024-09-22 07:55:51