添加合计行,求教sql问题

select c.dept_name,a.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_num,dept_code,year,acct_month from BASE_PERSON
group by dept_code,year,acct_month
) a LEFT JOIN
(select count(PERSION_NAME) T_num,dept_code,year,acct_month from BASE_PERSON
group by dept_code,year,acct_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_name,a.B_num,b.T_num,c.dept_code
ORDER BY c.dept_code
添加一行合计该怎么做呢?

能说清楚点吗?你的表结构列一下,你的临时表也列一下,然后说说你到底想合计个啥?你是要在滚动累计最后一行出合计么?是的话用过程累加一下就好了

参看ROLLUP的用法
https://technet.microsoft.com/en-us/library/ms189305(v=sql.90).aspx