From this table, after querying I want to get the child column that shows the number of the child for each id.
I want:
CodePudding user response:
A scalar subquery will produce the data you want. For example:
select
t.*,
(select count(*) from t b where b.parent_id = t.id) as child
from t