๊ฐœ๋ฐœ Life

์˜ค๋ผํด ๊ณ„์ธตํ˜•์ฟผ๋ฆฌ mysql(maria db)๋กœ ๋ณ€๊ฒฝ

SOBOB 2019. 1. 9. 14:00
๋ฐ˜์‘ํ˜•
select  id,
        name,
        parent
from    (select * from RecursionTest
         order by parent, id) products_sorted,
        (select @pv := '3') initialisation
where   find_in_set(parent, @pv) > 0
and     @pv := concat(@pv, ',', id)


์ถœ์ฒ˜: http://bulkywebdeveloper.tistory.com/109 [๊ฑด๊ฐ•ํ•œ ์ฝ”๋”ฉ]




with recursive cte (id, name, parent) as
(
 select     id,
            name,
            parent
 from       recursiontest
 where      parent = 3
 union all
 select     r.id,
            r.name,
            r.parent
 from       recursiontest r
 inner join cte
         on r.parent = cte.id
)
 
select * from cte;



์ถœ์ฒ˜: http://bulkywebdeveloper.tistory.com/109 [๊ฑด๊ฐ•ํ•œ ์ฝ”๋”ฉ]

๋ฐ˜์‘ํ˜•