34,590
社区成员
发帖
与我相关
我的任务
分享
Uid A B C
-------------------- ----------- ----------- -----------
123 1 2 3
2EE 4 5 6
SSO 5 5 5
汇总 10 12 14
(4 行受影响)
if object_id('tablename') is not null
drop table tablename
create table tablename(Uid nvarchar(20),A int,B int,C int)
insert into tablename
select '123',1,2,3 union all
select '2EE',4,5,6 union all
select 'SSO',5,5,5
(select *
from tablename)
union all
select '汇总',sum(A),sum(B),sum(C)
from tablename
select
isnull(uid,'') as uid,
sum(a) as a,
sum(b) as b,
sum(c) as c
from tablename
group by uid
with rollup
order by case when uid is null then 1 else 0 end