有两张桌子:银行和分行。
银行有: bank_name [红色,蓝色,绿色,] bank_ID [1,2,3]
分支机构: bank_ID [1,1,2,3], branch_name [wright,james,will,phil]
我需要返回带有更多分支的bank_name ,并且它是数字。
是否可以使用子查询执行此操作?谢谢!
编辑答案:
SELECT ban.bank_name,COUNT(bra.branch_name)
来自分支机构天然加入银行禁令
GROUP BY bank_name
HAVING COUNT(bra.branch_name)=(SELECT MAX(COUNT(branch_name)) 从分支机构 GROUP BY bank_id);
我遇到了自然连接的问题,以及子查询如何影响它。
希望它有所帮助!
答案 0 :(得分:0)
SELECT b.bank_id, COUNT(*)
FROM
bank b
LEFT JOIN branches br ON br.bank_ID = b.bank_ID
GROUP BY b.bank_id
ORDER BY COUNT(*) DESC
LIMIT 1