The Report

  • + 0 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