参考
自己 join 自己
SELECT a.id, count( b.parent_id )
FROM table1 a
LEFT JOIN table2 b
ON a.id = b.parent_id
GROUP BY a.id;
SELECT a.id, count( b.parent_id )
FROM table1 a
LEFT JOIN table2 b
ON a.id = b.parent_id
GROUP BY a.id;
本文标题:mysql 同一张表里面,统计父亲有多少个孩子
本文链接:https://www.haomeiwen.com/subject/trfkkctx.html
网友评论