如何使用MySQL从电话号码中提取区号?
假设我们有一个号码列表,然后我们要从中获取区号。这些区号例如是号码的前3位数字。LEFT()为此使用MySQL的功能。
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> AreaCodes varchar(100) -> );
使用insert命令在表中插入一些记录。在这里,假设我们包含了号码-
mysql> insert into DemoTable values('90387568976') ;
mysql> insert into DemoTable values('90389097878' ;
mysql> insert into DemoTable values('56789008799');
mysql> insert into DemoTable values('45679008571');
mysql> insert into DemoTable values('45679008536);使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------------+ | AreaCodes | +------------+ | 90387568976| | 90389097878| | 56789008799| | 45679008571| | 45679008536| +------------+ 5 rows in set (0.00 sec)
以下是查询以获取可用的区号-
mysql> select distinct LEFT(AreaCodes,4) from DemoTable
这将产生以下输出-
+-------------------+ | left(AreaCodes,4) | +-------------------+ | 9038 | | 5678 | | 4567 | +-------------------+ 3 rows in set (0.13 sec)
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志