3
我有一個像marksheet表:MySQL的支點查詢和排序查詢
ID STUDENT_ID Branch_id Class_id Exam_id Subject_id Numbers Date 1 653 5 1 1 8 60 2012-01-01 2 653 5 1 1 9 40 2012-01-01 3 653 5 1 1 10 80 2012-01-01 4 653 5 1 1 11 50 2012-01-01 5 653 5 1 1 12 65 2012-01-01 6 653 5 1 1 13 33 2012-01-01 7 653 5 1 1 15 86 2012-01-01 8 222 5 1 1 8 100 2012-01-01 9 222 5 1 1 9 80 2012-01-01 10 222 5 1 1 10 92 2012-01-01 11 222 5 1 1 11 50 2012-01-01 12 222 5 1 1 12 65 2012-01-01 13 222 5 1 1 13 33 2012-01-01 7 222 5 1 1 15 86 2012-01-01
我想獲得排名我這個question
得到答案還當我拿來一切階級結果我用支點查詢:
SELECT stu_id, sum(numbers) AS total, branch_id, depart_id, class_id,
SUM(IF(subject_id =1, numbers, 0)) AS MAth,
SUM(IF(subject_id =2, numbers, 0)) AS Eng,
SUM(IF(subject_id =3, numbers, 0)) AS Science
FROM marksheet where branch_id = 1 AND depart_id = 1
AND class_id = 1 GROUP BY stu_id ORDER BY total DESC
我想在我的班級查詢(透視查詢)中獲得排名?我想要統計第一位的學生人數以及第二位和第三位的人數?
需要的數據樣本:
ID Name Math English Science Total Percent Position Rank
任何一個可以幫助?
你可以讓這個子查詢,並從這個結果執行一個類似的組? –
我無法理解每一個可能的答案我wan – Zia
是數字的結果? –