Monday 15 April 2013

sql - mysql query to calculate student grades rows to get an order by asc or desc -



sql - mysql query to calculate student grades rows to get an order by asc or desc -

in mysql database table examinations pupil appearing based on subjects he/she wrote, bellow query outputting students sat exam tagged assessment_id = 1

select distinct exam.fname, exam.lname, exam.idcandidate examinations exam inner bring together examinfo info on exam.subject_id = info.subjectid info.assessment_id = '1'

now sort query based on total scores pupil have on his/her subjects either desc or asc

the field stores pupil scores called 'score' examinations table, please help me how can archive or right way of doing it.

total calculated each exam.fname , each exam.lname , each exam.idcandidate

select exam.fname, exam.lname, exam.idcandidate, sum(exam.score) total examinations exam inner bring together examinfo info on exam.subject_id = info.subjectid info.assessment_id = '1' grouping exam.fname, exam.lname, exam.idcandidate order total desc;

total calculated each exam.idcandidate

select distinct exam.fname, exam.lname, exam.idcandidate examinations exam inner bring together examinfo info on exam.subject_id = info.subjectid inner bring together (select idcandidate, sum(score) total examinations grouping idcandidate) tot on exam.idcandidate = tot.idcandidate info.assessment_id = '1' order tot.idcandidate desc;

total calculated each exam.idcandidate (for assessment_id = '1')

select distinct exam.fname, exam.lname, exam.idcandidate examinations exam inner bring together examinfo info on exam.subject_id = info.subjectid inner bring together (select ex.idcandidate, sum(ex.score) total examinations ex inner bring together examinfo ei on ex.subject_id = ei.subjectid ei.assessment_id = '1' grouping idcandidate) tot on exam.idcandidate = tot.idcandidate info.assessment_id = '1' order tot.idcandidate desc;

mysql sql

No comments:

Post a Comment