2017-06-29 93 views
-1

查询以Guardian表格的字母顺序显示所有“父(丈夫)”名称,其中包含“妻子”总数(使用嵌套查询查找妻子数)。有关嵌套查询主题的SQL查询

enter image description here

+0

欢迎加盟SO和组。你的问题很难理解。请尝试更精确和具体的问题,以便其他人可以更轻松地为您提供帮助。所以也这些建议:https://stackoverflow.com/help/how-to-ask – petezurich

回答

0

你可以使用一个自通过

select a.guardianName as husband_name, count(*) as count_of_wives 
from my_table a 
left join my_table b on b.husband_id = a.guardianId 
where a.husband_id is null 
group by a.guardianName 
+0

thanx它的工作:) – james

+0

好,如果我的回答是正确的,请将其标记为已接受...看看这里如何 http:// meta .stackexchange.com /问题/ 5234 /如何-不接受-的回答工作 – scaisEdge