Please can someone tell me what I'm not doing right. Here is a query I want to execute, but nothing happens when I run the command. I'm new to SQL so pardon my mistake, if any.
SELECT t.*,
COUNT(DISTINCT t.subjects) AS subjectenrollment,
u.urefnumber,
u.uresidence
FROM
(
SELECT r.*,
@curRank := IF( @prevRank = finalscore, @curRank, @incRank ) AS position,
@incRank := @incRank + 1,
@prevRank = finalscore
FROM studentsreports r,
(
SELECT @curRank := 0,
@prevRank = NULL,
@incRank := 1
) c
ORDER BY finalscore ASC
) t LEFT JOIN studentstbl u ON t.studref = u.urefnumber
WHERE t.author = :staff
AND t.studentname = :student
AND t.academicyr = :year
AND t.academicterm = :term
AND t.program = :program
AND t.classes = :level
AND t.subjects = :subject;
As it can be seen from the code, I'm trying to fetch students records, and include a column for position in each subject, as well as the number of students offering each subject. More over, I want to include each student's residential status, which is also in a different table.
At a point, I even want to add their accumulated raw scores, that is, the summation of all the marks obtained in each subject, but I don't know how to even make that possible. A friend has already suggestted acheiving that in separate queries, but unfortunately, I could get that well.
Please, I will be very grateful for your help. Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…