The Report

  • + 2 comments

    Your ordering is not correct; if you look at your null values, it's sorting a grade of 3 before grades of 4, 6, and 7. Your order by clause doesn't makes sense and needs to be changed to this:

    select 
        case when g.grade > 7 then s.name else NULL end,
        g.grade, 
        s.marks 
    from students s 
        inner join grades g 
        on s.marks between g.min_mark and g.max_mark 
    order by g.grade desc, s.name asc;
    

    Don't overcomplicate.