你印象最深的一道SQL题目是什么?
在“找出各项考试中的佼佼者”这题目中,我觉得挺有意思的。我用的是子查询和联结的方式。
SELECT t.name AS test_name, s.name AS student_name, ta.score FROM TestAttempt ta JOIN Student s ON s.id = ta.studentId JOIN Test t ON t.id = ta.testId WHERE ( SELECT COUNT(DISTINCT score) FROM TestAttempt WHERE testId = ta.testId AND score > ta.score )
具体来说,子查询 (SELECT COUNT(DISTINCT score) FROM TestAttempt WHERE testId = ta.testId AND score > ta.score)
赞0
踩0