mysql查询|Mybatis查询

mysql查询|Mybatis查询,第1张

1、mysql肯定可以实现

2、树形结构的实现其实很简单的,建议你看下ztree的官方api,你只需要按照数据结构递归查询出父子节点的数据即可

3、mybatis是java中实现的方式了,至于你想怎么优化,最后都是递归查询父子节点的数据

select id,

name,

pid

from(select * from products

order by pid, id) products_sorted,

(select @pv := '1') initialisation

where find_in_set(pid, @pv)

and length(@pv := concat(@pv, ',', id))

select t1.name,t2.name,t3.name,t4.name

from tb as t1

left join tb as t2 on t2.pid=t1.id and t2.pid=1

left join tb as t3 on t3.pid=t2.id and t3.pid=2

left join tb as t4 on t4.pid=t3.id and t4.pid=3

where pid=0


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/6134905.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-16
下一篇2023-03-16

发表评论

登录后才能评论

评论列表(0条)

    保存