日期:2014-05-18  浏览次数:20509 次

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

------解决方案--------------------
表中没有表示是联通、移动还是电信的分类字段?
------解决方案--------------------
case when then else end 来判断 substring()前面几个数字是属于哪里的号码
------解决方案--------------------
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