我有一张看起来像这样的桌子
id name answer question
1 john correct 1
1 john correct 2
1 john correct 3
1 john wrong 4
2 lee wrong 1
2 lee correct 2
2 lee correct 3
3 ana correct 1
3 ana wrong 2
我希望能够获得所有唯一用户的列表,并查看他们有多少问题是正确的,有多少问题是错误的。
我尝试过这样的事情,但我似乎无法让它工作:
SELECT id, user_id, name, question_id, (select count(answer) from table where answer = 'CORRECT') as correct, (select count(answer) from table where answer= 'WRONG') as wrong FROM table GROUP BY user_id
有人可以帮我让我走上正轨吗?谢谢