I have a table structure, which, simplified, looks something like this.
grandparents
id
name
parents
id
grandparent_id
name
children
id
parent_id
name
I know, I can count the number of children a parent has like this:
select
name,
( select count (*) from children c where c.parent_id = p.id ) as count
from p parents;
My question is, how do I count the number of children that are related to a grandparent. The table structure cannot be changed, and I want a single SELECT statement. Is that possible?
Thanks in advance.