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条语句该怎样写?

解决方案 »

  1.   

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

  2.   

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

  3.   

    Haiwer(海阔天空) ,你的答案正确,但不是我提问的初衷.我想了解isnull是不是对聚合函数中的组合字段不生效!