0
輸出:https://www.dropbox.com/s/q9bjrzndbzj0l2i/test3.PNG?dl=0閱讀ROW_NUMBER
如果我想只得到位置(ROW_NUMBER)= 3,如果讓我們說的Stud_ID = 4如何合併查詢到當前的代碼?
SET @row_num = 0;
SELECT @row_num := @row_num + 1 as Position, s.*
FROM
(
SELECT
Student.Stud_ID, Student.Stud_Name, Student.Stud_Class, SUM(Grade.Percentage) AS Points
FROM Student, Student_Subject, Grade
WHERE Student.Stud_ID = Student_Subject.Stud_ID
AND Student_Subject.Stud_Subj_ID = Grade.Stud_Subj_ID
AND Student.Stud_Form = '1'
AND Grade.Quarter = '1'
GROUP BY Student.Stud_ID
ORDER BY Points DESC
) AS s;
謝謝!!
明白了!謝啦 –