case when then else end 来判断 substring()前面几个数字是属于哪里的号码
那岂不是要写3个sql了,用一个sql查怎么写啊
是一个SQL语句了 case when left(号码,3) in ('137','134','138') then '移动' when left(号码,3) in ('186','151') then '电信' else '联通' end类似。
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
要怎么查啊
case when left(号码,3) in ('137','134','138') then '移动'
when left(号码,3) in ('186','151') then '电信'
else '联通' end类似。
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