同一張地區表中根據漢字查詢地區的程式碼
阿新 • • 發佈:2019-01-11
表結構
1 CREATE TABLE `t_sys_city` ( 2 `id` varchar(64) NOT NULL COMMENT '標示', 3 `city_name` varchar(64) DEFAULT NULL COMMENT '城市名稱', 4 `parent_id` varchar(64) DEFAULT NULL COMMENT '父id', 5 `city_level` int(11) DEFAULT NULL COMMENT '級數', 6 `initial` varchar(16) DEFAULT NULL COMMENT '首字母', 7 `alphabet` varchar(64) DEFAULT NULL COMMENT '全拼', 8 `area_code` varchar(16) DEFAULT NULL COMMENT '區號', 9 `state` char(1) DEFAULT '0' COMMENT '表狀態(0:正常;1:作廢)', 10 `create_name` varchar(32) DEFAULT NULL COMMENT '建立人', 11 `create_time` varchar(32) DEFAULT NULL COMMENT '建立時間', 12 PRIMARYKEY (`id`), 13 KEY `parent_id` (`parent_id`) USING BTREE, 14 KEY `state` (`state`) USING BTREE 15 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;
-- 右外連線 SELECT p.id provinceId, c.id cityId, a.id areaId FROM t_sys_city p RIGHT JOIN t_sys_city c ON p.id = c.parent_idRIGHT JOIN t_sys_city a ON c.id = a.parent_id WHERE p.city_name LIKE '山東%' AND c.city_name LIKE '濟南%' AND a.city_name LIKE '歷下%'; -- 內連線 SELECT p.id provinceId, c.id cityId, a.id areaId FROM t_sys_city p, t_sys_city c, t_sys_city a WHERE p.id = c.parent_id AND c.id = a.parent_id AND p.city_name LIKE '山東%' AND c.city_name LIKE '聊城%' AND a.city_name LIKE '冠縣%';