Need a solution to solve sql problem

Copper Contributor

Hello everyone,

This is Sophie, I am new to this community.

Currently I am stuck on an sql question, is anyone able to help on it?

 

Question:

You are given two tables: Students and GradesStudents contains three columns ID, Name and Marks.

Students.png

 

Grades contains the following data:

Grades.png

 

Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered first. If there is more than one student with the same grade (8-10) assigned to them, order those particular students by their name alphabetically. Finally, if the grade is lower than 8, use "NULL" as their name and list them by their grades in descending order. If there is more than one student with the same grade (1-7) assigned to them, order those particular students by their marks in ascending order.

Write a query to help Eve.

 

Below is my solution, but I am aware I am missing the key to join the table, which is exactly where I am stuck, as I can't find a proper way to join. Can anybody help to look at it and give a hint?

Thanks guys.

 

SELECT Students.Name, Students.Marks, CASE WHEN Marks BETWEEN 90 AND 100 THEN Grade = 10 ELSE NULL END, CASE WHEN Marks BETWEEN 80 AND 89 THEN Grade = 9 ELSE NULL END, CASE WHEN Marks BETWEEN 70 AND 79 THEN Grade = 8 ELSE NULL END FROM Students FULL JOIN Grades GROUP BY Grade ORDER BY Name ASC, Marks ASC;

0 Replies