MySQL组中的查询错误

时间:2015-02-11 08:06:35

标签: mysql sql

我正在使用

形式的SQL查询
   create table tb5
   SELECT count(*) as count, question, responsesummary, questionid from tb4 
   where responsesummary!= rightanswer group by  question,responsesummary 

我获得的结果如下

        count                 question             responsesummary     id
         5                      q1                     abc            331
         6                      q1                     def            331
         5                      q1                     abc            331

相反,我想要

       count                 question             responsesummary      id 
         10                      q1                     abc           331
         6                      q1                     def             331

我做错了什么?是否可以向现有结果添加新查询并获得所需的输出?

1 个答案:

答案 0 :(得分:0)

SELECT 
      COUNT(*) as count, 
      question, 
      responsesummary,
      question_id
FROM tb5
WHERE responsesummary!= rightanswer GROUP BY responsesummary,question_id,question