如何使用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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短