select A,(select sum(aa) from....) as total,(select...) as total1
from table1
union all
select 'totala',sum(aa),sum(...............
from table1这种方法可以补.
from table1
union all
select 'totala',sum(aa),sum(...............
from table1这种方法可以补.
select A,(select sum(aa) from....) as total,(select...) as total1
into #tt
from table1
--加入汇总信息
insert #tt select 'totala', sum(total), sum(total1) from #tt
--查询
select * from #tt
--清除
drop table #tt
如果不用临时表的话,还可以这样做。(方法和阿来的类似, 不过,我不赞成他那样做。他那样有点复杂, 过于精巧。)
*/
select A,(select sum(aa) from....) as total,(select...) as total1
from table1
union all
select 'totala', sum(total), sum(total1)
from (select A,(select sum(aa) from....) as total,(select...) as total1
from table1)t
那么使用rollup处理更有效率.