mysql查询直接下级和所有下级


SELECT id
FROM (
SELECT *
FROM ty_hotel_product
WHERE parent_product_id > 0

ORDER BY parent_product_id DESC
) realname_sorted, (
SELECT @pv := 2
) initialisation
WHERE FIND_IN_SET(parent_product_id, @pv) > 0
AND (@pv := concat(@pv, ',', id))




select id from (
select t1.id,
if(find_in_set(parent_product_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
from (
select id,parent_product_id from ty_hotel_product t where t.status = 1 order by parent_product_id, id
) t1,
(select @pids := 1) t2
) t3 where ischild != 0


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM