首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

请问:关于 with rollup 的有关问题

2012-01-21 
请教:关于 with rollup 的问题selecta1isnull(a1, 合计 ),a2,count(*)fromtablegroupbya1,a2withrollup执

请教:关于 with rollup 的问题
select   a1=isnull(a1, '合计 '),a2,count(*)  
        from   table  
        group   by   a1,a2   with   rollup  

执行上面语句,最后一行有 "合计 ",而执行下面语句,却没有 "合计 ":

select   a1=isnull(a1+ '- '+a2), '合计 '),count(*)  
        from   table  
        group   by   isnull(a1+ '- '+a2), '合计 ')   with   rollup  

请问第2条语句该怎样写?

[解决办法]
select a1=case when grouping(a1+ '- '+a2)=1 then '合计 ' end,count(*)
from table
group by (a1+ '- '+a2) with rollup

[解决办法]
select a1=isnull(x, '合计 '),count(*)
from (
select a1+ '- '+a2 as x
from table
) as t
group by x with rollup

热点排行