sql查地区省市县

-- db_yhm_city   
SELECT * FROM db_yhm_city WHERE class_parent_id = 1 -- 海南 class_id = 9 港、奥、台 class_id = 33、34、35   
  
SELECT * FROM db_yhm_city WHERE class_parent_id =169   
  
SELECT d1.class_name, d2.class_name, d3.class_name FROM db_yhm_city d1    
RIGHT JOIN db_yhm_city d2 ON d1.class_id = d2.class_parent_id    
RIGHT JOIN db_yhm_city d3 ON d2.class_id = d3.class_parent_id   
WHERE d3.class_id = 1445   
  
-- tb1_publicarea   
SELECT * FROM tbl_publicarea WHERE parentid = 0 -- 海南 areaid = 21   
  
SELECT * FROM tbl_publicarea WHERE parentid = 21   
  
SELECT t1.areaname, t2.areaname, t3.areaname FROM tbl_publicarea t1    
RIGHT JOIN tbl_publicarea t2 ON t1.areaid = t2.parentid    
RIGHT JOIN tbl_publicarea t3 ON t2.areaid = t3.parentid    
WHERE t3.areaid = 264   
  
-- t_area   
SELECT * FROM t_area WHERE parentid IS NULL -- 海南 id = 460000   
  
SELECT * FROM t_area WHERE parentid = 460000  -- 省直辖 id = 469000   
  
SELECT * FROM t_area WHERE parentid = 469000   
  
SELECT a1.name, a2.name, a3.name FROM t_area a1    
RIGHT JOIN t_area a2 ON a1.id = a2.parentid    
RIGHT JOIN t_area a3 ON a2.id = a3.parentid    
WHERE a3.id = 419001   
  
SELECT * FROM t_area WHERE NAME LIKE "%省直辖%"  
  
SELECT * FROM t_area WHERE id = 419000 -- 省直辖  

你可能感兴趣的