0

我有一张桌子,我一直在发布评论类型、金额等。

PostExtras
- id
- amount
- post_id (foreign key)
- comment_type (foreign key)
- ...

comment_type
- id
- name

我想选择具有重复评论类型的帖子。

例子:

- id     - amount    - post_id    - comment_type
 1         20          23           1
 2         45          23           2
 3         80          28           1
 4         78          28           2
 5         56          23           1

第 1 行和第 5 行实际上是相同的。

4

2 回答 2

1

如果我理解正确,请使用COUNT、GROUP BY 和 HAVING

SELECT *, COUNT(*) AS itemcount FROM PostExtras 
GROUP BY post_id, comment_type
HAVING itemcount >= 2
于 2011-06-24T11:51:38.687 回答
0
SELECT post_id FROM PostExtras
GROUP BY post_id, comment_type
HAVING COUNT(comment_type) > 1
于 2011-06-24T11:51:19.620 回答