省市区三级地区数据库导入

1.高德地图下载源文件

https://lbs.amap.com/api/javascript-api/download

 

 

 

  2.导入数据库

 

 

 

 3.处理数据

##source最后两位为sort
UPDATE `Sheet1$` SET sort = SUBSTR(source,5);
##source的0000结尾为省000或者00结尾为市
UPDATE `Sheet1$` SET LEVEL = 3;
UPDATE `Sheet1$` SET LEVEL = 2 WHERE source RLIKE '.000$' OR source RLIKE '.00$';
UPDATE `Sheet1$` SET LEVEL = 1 WHERE source RLIKE '.0000$';
##更新id,省-SUBSTR(source,1,2)市-SUBSTR(source,1,4)区-source
UPDATE `Sheet1$` SET id = SUBSTR(source,1,2) WHERE LEVEL = 1;
UPDATE `Sheet1$` SET id = SUBSTR(source,1,4) WHERE LEVEL = 2;
UPDATE `Sheet1$` SET id = source WHERE LEVEL = 3;
##更新父id
UPDATE `Sheet1$` SET pid = SUBSTR(source,1,2) WHERE LEVEL = 2;
UPDATE `Sheet1$` SET pid = SUBSTR(source,1,4) WHERE LEVEL = 3;

4.检查一下,导入目标表

##导入目标表
INSERT INTO `area`(id,NAME,pid,sort,LEVEL,CODE) SELECT id,NAME,pid,sort,LEVEL,CODE FROM `Sheet1$`
##更新错误的部分-香港澳门特别行政区
UPDATE `area` SET pid='81',LEVEL=2 WHERE pid='8100';
UPDATE `area` SET pid='82',LEVEL=2 WHERE pid='8200';

 

posted @ 2020-06-02 16:26  缘故为何  阅读(709)  评论(0编辑  收藏  举报