做一些练习,我不知道如何进行查询
有这2张桌子
StudentTable(IDstudent,....)
考试(IDexam,...,学生,...,结果)
哪里
考试中的学生参考ID学生中的学生
resutl具有布尔值
例
StudentTable
IDstudent
S0001
S0002
S0003
EXAM
IDexam student result
1 S0001 true
2 S0002 true
3 S0002 true
4 S0003 false
查询必须显示考试中真实人数最多的学生ID和人数
在例子的情况下
S0002 2
我试过了
SELECT
student, count(1)
FROM
Exam E join StudentTable S on E.student=S.id_student
WHERE result='true'
GROUP by student
我有的是
S0001 1
S0002 2
但是我不知道怎么走
我能怎么做?
这是指向架构http://sqlfiddle.com/#!2/895ea/8的链接
最佳答案
尝试这个:
SELECT
student, count(1)
FROM
Exam E join StudentTable S on E.student=S.id_student
WHERE result='true'
GROUP by student
ORDER by 2 DESC
LIMIT 0,1
MySQL中的LIMIT(N,N)子句等效于T-SQL中的TOP(N)