分组汇总
select * from test
select ( case when len(id)>20 then name else id end ) name ,金额,数量 from
(
SELECT name, isnull(id,'汇总') as id, sum(金额) 金额 , SUM(数量) 数量 from
(select *, cast(newid() as varchar(60)) as id from test) a
group BY name,id with CUBE
) b
where name is not null