We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- SQL
- Basic Join
- The Report
- Discussions
The Report
The Report
Sort by
recency
|
3234 Discussions
|
Please Login in order to post a comment
SELECT CASE WHEN G.Grade > 7 THEN S.Name ELSE 'NULL' END, G.Grade, S.Marks FROM STUDENTS S LEFT JOIN Grades G ON S.Marks BETWEEN G.Min_Mark AND G.Max_Mark ORDER BY G.Grade DESC, CASE WHEN G.Grade > 7 THEN S.Name ELSE S.Marks END ASC
select case when (select grade from grades where s.marks between min_mark and max_mark)>= 8 Then s.name else NULL end, (select grade from grades where s.marks between min_mark and max_mark) as grade_of_student, s.marks from students s order by grade_of_student desc, name asc, marks asc;
Pertinent to MS SQL SERVER, the compact T-SQL solution is as follows:
-- MS SQL Server
select name = case when grade < 8 then null else name end, grade, marks from students, grades where students.marks >= grades.min_mark and students.marks <= grades.max_mark order by grade desc, name, marks
WITH Full_Table AS( SELECT s.name AS name,g.grade AS grade,s.marks AS marks FROM Students s INNER JOIN Grades g ON s.marks BETWEEN g.Min_Mark AND g.Max_Mark )
SELECT (CASE WHEN grade>=8 THEN name ELSE null END), grade, marks FROM Full_Table ORDER BY grade DESC, name;