SQL好久没写了,一下竟然不会写,给整不会了
我尝试过的方法 想知道正确答案
SELECT * from student_score
LEFT JOIN course on course.id=student_score.course_id
LEFT JOIN student ON student_score.studentid=student.id
GROUP BY student_score.course_id
ORDER BY student_score.score DESC
limit(0,3)
学生表 student( id name)
课程表 course (id course_name)
student_score (id student_id score course_id)
查总分排名前三大学生的名字
SELECT s.id,s.name,SUM(ss.score) totalScore
FROM
student s
LEFT JOIN
student_score ss
ON s.id = ss.student_id
GROUP BY ss.student_id
ORDER BY totalScore DESC
LIMIT 0,3
SELECT * FROM student_socre AS score
LEFT JOIN student AS s on s.id = score.student_id
LEFT JOIN course AS c on c.id = course_id
GROUP BY s.id,s.name
ORDER BY SUM(score.score) DESC
LIMIT 0,3