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.
with markwise_grade as(
SELECT s.id,s.name,s.marks,g.grade
from students s inner join grades g
on s.marks>=min_mark and s.marks<=max_mark
),
top_grade as(
select markwise_grade.name as name,markwise_grade.grade,markwise_grade.marks
from markwise_grade
where markwise_grade.grade>=8
),
low_grade as(
select "NULL" as name,markwise_grade.grade,markwise_grade.marks
from markwise_grade
where markwise_grade.grade<8)
select * from top_grade
union all
select * from low_grade
order by grade desc,name,marks
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Report
You are viewing a single comment's thread. Return to all comments →
with cte and union
with markwise_grade as( SELECT s.id,s.name,s.marks,g.grade from students s inner join grades g on s.marks>=min_mark and s.marks<=max_mark ), top_grade as( select markwise_grade.name as name,markwise_grade.grade,markwise_grade.marks from markwise_grade where markwise_grade.grade>=8 ), low_grade as( select "NULL" as name,markwise_grade.grade,markwise_grade.marks from markwise_grade where markwise_grade.grade<8) select * from top_grade union all select * from low_grade order by grade desc,name,marks