Three tables, for example, A grandpa Son of b C grandson A grandpa son also have more than one son has multiple
The query according to the grouping grandpa son how many, how many grandchildren as follows
Grandpa total name son so Zhang SAN May 15 Li si 8 and 24
CodePudding user response:
Here, there is no primary key, can also be the only value, SELECT table grandpa. Grandpa, COUNT (DISTINCT son table. The primary key) son, total COUNT (DISTINCT grandchildren tables. The primary key) total grandson FROM grandpa table Son son LEFT the JOIN table ON table and grandpa table of correlation, multiple correlation with the and separated, Grandson LEFT the JOIN table ON son table and the table of correlation and multiple correlation with the and separated, Table GROUP BY grandpa. Grandpa;