[英]want to get country area code from phone number present in mysql db
I'm having phone number 1212010089
and want to know from which country I'm getting this number.I do have a table_1
which is having column1 area_code
where lots of area codes are available and column2 location
which is having an equivalent location according to that area_code
the maximum length of area_code
is 7 in it so please suggest me an appropriate sql query by which I can find the location
from that number.我的电话号码是1212010089
,想知道我是从哪个国家/地区收到这个号码的。我确实有一个table_1
,它有 column1 area_code
,其中有很多区号可用,column2 location
根据该位置具有等效位置area_code
area_code
最大长度是 7 所以请建议我一个合适的 sql 查询,通过它我可以从那个号码找到location
。 Thanks in advance.提前致谢。
Try something like:尝试类似的东西:
SELECT location
FROM table_1
WHERE '237690000000' LIKE CONCAT(area_code,'%')
AND LENGTH(area_code)=
(SELECT MAX(LENGTH(area_code))
FROM table_1
WHERE '237690000000' LIKE CONCAT(area_code,'%'));
See Demo on DB-SQL Fiddle .请参阅DB-SQL Fiddle 上的演示。
you can also try this:你也可以试试这个:
SELECT location FROM table_1 WHERE '23769111111' LIKE CONCAT(area_code,'%') ORDER BY LENGTH area_code DESC LIMIT 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.