问题:解决方案: 问题:数据结构如下: id pid qid33 0 22855 52 22854 52 22852 0 228 想查出,每条记录存在的子节点数id为自增,pid是父ID 最好是SQL语句来完成,不要存储过程实现效果如下 id 子结点数 33 0 52 2 解决方案:select id,(select count(*) from 数据结构如下 where pid=t.id) as 子结点数 from 数据结构如下 t where pid=0