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
|
3382 Discussions
|
Please Login in order to post a comment
**MS SQL ** key takeaways:- case in order by; and case in left joins; and union cannot be done in two different selects with - diff order by clauses for two selects
`
select if (g.grade >= 8, s.name, NULL) as names, g.grade, s.marks from students s inner join grades as g on s.marks <= g.max_mark and s.marks >= g.min_mark order by g.grade desc, name asc, marks asc;
SELECT CASE WHEN g.grade >= 8 THEN s.name ELSE 'NULL' END AS name, g.grade, s.marks FROM students s JOIN grades g ON s.marks BETWEEN g.min_mark AND g.max_mark ORDER BY g.grade DESC,
CASE WHEN g.grade >= 8 THEN s.name END ASC, CASE WHEN g.grade < 8 THEN s.marks END ASC;
SELECT CASE WHEN g.grade < 8 THEN null ELSE s.name END , g.grade, s.marks FROM students s JOIN grades g ON s.marks BETWEEN g.min_mark AND g.max_mark ORDER BY g.grade DESC, s.name ASC;