1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| SELECT id, name, parent_id FROM (SELECT t1.id, IF(FIND_IN_SET(parent_id, @parentId) > 0, @parentId:=CONCAT(@parentId, ',', id), 0) AS ischild, name,parent_id FROM (SELECT id, parent_id, name FROM sys_city t ORDER BY parent_id , id, name) t1, (SELECT @parentId:= #{parentId}) t2) t3 WHERE ischild != 0 union select id, name, parent_id from sys_city where id = #{parentId};
|