2017-06-29 174 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