select count(b.mobileno) as 参与次数 ,max(case when custtype='中奖客户' then b.mobileno else null end)as 手机号,count(case when custtype='中奖客户' then b.mobileno else null end) as 中奖次数 
from t_base b
group by b.mobileno

解决方案 »

  1.   

    select XX
      sum( case when  XX then 1 else 0 end)
    group by XX
    order by XX
      

  2.   

    select 参与次数=(select sum(b.mobileno) from t_base where mobileno=b.mobileno)  ,b.mobileno as 手机号,count(b.custtype) as 中奖次数 
    from t_base b
    where b.custtype='中奖客户'
    group by b.mobileno
      

  3.   

    select 参与次数=(select sum(1) from t_base where mobileno=b.mobileno)  ,b.mobileno as 手机号,count(b.custtype) as 中奖次数 
    from t_base b
    where b.custtype='中奖客户'
    group by b.mobileno