如何计算具有相同值的答案?

时间:2011-12-13 14:40:56

标签: sql

我有一张这样的表:

--Table Answer--
Id     Question_id  Attendee_id  Answer
100    qst1          001         Name1
101    qst2          001         Name1
102    qst3          002         Name2

我想知道如何计算具有相同值的答案?

4 个答案:

答案 0 :(得分:2)

A standard SQL aggregate

SELECT Answer, COUNT(*) FROM MyTable GROUP BY Answer

答案 1 :(得分:2)

Select Answer, Count(*) FROM answer GROUP BY Answer

答案 2 :(得分:2)

SELECT answer,COUNT(*) FROM table
GROUP BY answer

答案 3 :(得分:1)

对于每个问题?

SELECT
    Question_id,
    Answer,
    COUNT(1) qty
GROUP BY
    Question_id, Answer

Question_idSELECT排除GROUP BY,如果您想要总计数,而不是按问题划分,尽管我认为这个数字不太有用。