使用列中不同值的数量作为 select 条件

Use number of distinct values from a column as select criteria

我在 mysql 数据库中有以下模式

Field       |  Type   |    Null  |  Key  |  Default  |  Extra
------------+---------+----------+-------+-----------+---------
answerId     int(11)      NO       PRI     NULL
answerDate   datetime     YES              NULL
creationDate datetime     YES              NULL
questionId   int(11)      NO       PRI     0
url          text         YES              NULL
description  text         YES              NULL

这个table存储了一种问题和答案的关系,其中一个问题与一个或多个答案相关。我想做的是 select 有 5 个以上答案的问题。可以找回吗?

它对你有用吗?

SELECT questionId
FROM question_answer
GROUP BY questionId
HAVING COUNT(*) >5 

旁注。其他一些属性,urlcreationDate,和description,它们似乎没有描述问题和答案之间的关系...

 SELECT *
 FROM table 
 GROUP BY questionId   
 HAVING count(questionId)> 5

sql fiddle

Select questionID, count(*) as totalAnswers from qanda
group by questionID
having totalAnswers > 5

Example SQL Fiddle