我有2个表,帐户和程序。程序有一个外键account_id,将其与帐户绑定。
所以我有:
Account:
id
Name
Program:
id
account_id
name
我希望能够查询类似
的内容SELECT *, count(program.id) AS program_count From Account
但如果没有链接回帐户行的程序,则此功能无效。
有关做什么或如何做的任何见解或提示?
答案 0 :(得分:0)
SELECT Account.*, count(program.id) AS program_count
FROM Account
LEFT JOIN program
ON Account.id = Program.account_id
GROUP BY Account.id