【发布时间】:2011-09-25 14:00:59
【问题描述】:
我有两个表格,Snippets 和 Comments。 Snippets 有一个 Id 列,Comments 有一个 SnippetId 列。
我要统计每个sn-p的cmets个数。
我试过了:
SELECT
S.Id,
S.Title,
COUNT(*) AS CommentCount
FROM
Snippets S,
Comments C
WHERE
S.Id = C.SnippetId
但它不起作用。它返回 cmets 的总数,并且只返回一行。
我想要这样的结果:
Id | Title | CommentCount
1 | Test | 314
2 | Test2 | 42
我怎样才能做到这一点?
【问题讨论】: