我想要一个查询,该查询将产生输出,父项然后是所有子项,再次是下一个父项,直到所有子项

时间:2019-07-16 08:38:19

标签: mysql

这是我正在使用的查询,但仅提供id = 33

的输出
SELECT id, name ,parent_store_id, store_level FROM
(SELECT id, name ,parent_store_id, store_level,
       CASE WHEN id = 33 THEN @idlist := CONCAT(id)
            WHEN FIND_IN_SET(parent_store_id,@idlist) THEN @idlist := CONCAT(@idlist,',',id)
            END as checkId
FROM cx_store
ORDER BY id ASC) as T
WHERE checkId IS NOT NULL

enter image description here

0 个答案:

没有答案