表:table;字段:serialno主键,username名字,cellphone手机号码
怎么统计表中的移动号码和联通号码、电信号码的个数?
这个sql要怎么写啊?数据库是sql server2008
知道的帮帮忙

解决方案 »

  1.   

    没有,就根据cellphone查,手机号不是有133、135.....就根据这个
    要怎么查啊
      

  2.   

    case when then else end  来判断 substring()前面几个数字是属于哪里的号码
      

  3.   

    那岂不是要写3个sql了,用一个sql查怎么写啊
      

  4.   

    是一个SQL语句了
    case when left(号码,3) in ('137','134','138') then '移动'
         when left(号码,3) in ('186','151') then '电信'
         else '联通' end类似。
      

  5.   

    select t.type,count(*) from(
    SELECT *,
    case when left(cellphone,3) in('134','135','136','137','138','139','147','150','151','152','157','158','159','182','183','187','188') then 'td'
         when left(cellphone,3) in('130','131','132','155','156','185','186','145') then 'lt'
         when left(cellphone,3) in('133','153','180','189') then 'dx'
    else 'qt'
    end as type
    FROM table) as t
    group by t.type