I want to make a query that would return data about students who failed in a specific course, the report is looking like this-
studId, studName, last grade, year last course was taken, num of fails in this course.
so I'm having problems writing the correct SQL query to get the year on which the student took the course last time, and the grade he got on that year.
table data looks like this-
studId, courseId, yearTaken, grade, pass/fail
1111, 1, 2008, 20, failed
1111, 1, 2009, 30, failed
1111, 1, 2010, 40, failed
so the result of the query should be like this-
1111, 1, 2010, 40, 3(count numOfFails)
but I get always other year and grade like-
1111, 1, 2009, 30, 3
I made a view to order the table by studId, year DESC but I still get the same results as with the unordered table. since I can't use the ORDER BY before I do the GROUP BY to get the numOfFails I don't know what to try anymore..
here's my SQL for now-
SELECT * , count( viewstudent_course_orderedby.courseId ) AS numOfFails
FROM viewstudent_course_orderedby
WHERE viewstudent_course_orderedby.courseId = '1111'
GROUP BY viewstudent_course_orderedby.studentId