WITH RECURSIVE r AS (
SELECT * FROM test1 as t WHERE m_id = 18
union ALL
SELECT t.* FROM trade.merchant as t, r WHERE tree.par = r.m_id
)
SELECT * FROM r where stat = 1 ORDER BY m_id
它会一直递归调用,直到没有记录返回。
第一步,会得到 SELECT * FROM test1 as t WHERE m_id = 18 ,一条记录。并放在R中
然后再执行 SELECT t.* FROM trade.merchant as t, r WHERE tree.par = r.m_id 放入R中。 之后不断循环这一步。