求一个Sql的写法(可加分),兄弟们帮帮忙
有这么一个学生答案表: studentanswer
student_id test_id question_id model_answer student_answer
0000000001 00001 1 A A
0000000002 00001 1 A B
.
.
.
.
想在我想统计同一次考试的每一个题目有多少人答对了。用一个Sql写完,应该怎么写?
如果用n(n为question_id的个数)条sql语句,可以这样写:
select count(student_answer) as countanswer from studentanswer where test_id=1 and question_id=1 and model_answer=student_answer
不想这样写,是因为如果n很大的话,这样会很慢。