四表联合查询
SELECT class_t.classname, t1.studentname, t1.totalscore
FROM
class_t ,
(SELECT student_t.studentid, studentname, classid, SUM(score) totalscore
FROM student_t ,score_t
WHERE student_t.studentid = score_t.studentid
GROUP BY student_t.studentid, studentname, classid) t1,
(SELECT classid, MAX(totalscore) totalscore
FROM
(SELECT student_t.studentid, studentname, classid, SUM(score) totalscore
FROM student_t ,score_t
WHERE student_t.studentid = score_t.studentid
GROUP BY student_t.studentid, studentname, classid) t1
GROUP BY classid) t2
WHERE class_t.classid = t1.classid
AND t1.classid = t2.classid
AND t1.totalscore = t2.totalscore
上面的有点问题,这是改过的。
小弟初学,很多习惯还不是很好,有什么问题请各位多多指点。