来自以下 Mysql 查询
select (
case
when grade < 8 then null
else name
end
) as name,
grade, marks
from students
join Grades
ON Min_mark = (SELECT MAX(Min_mark) from grades where min_mark <= students.marks)
order by grade desc,name asc
我想根据等级值对订单进行排序,即
生成包含三列的报告:名称、等级和标记。报告必须按年级降序排列——即首先输入较高的年级。如果分配给同一年级 (1-10) 的学生不止一名,则按姓名字母顺序对这些特定学生进行排序。最后,如果成绩低于8,则用“NULL”作为他们的名字,并按照分数从小到大的顺序排列
select (
case
when grade < 8 then null
else name
end
) as name,
grade, marks
from students
join Grades
ON Min_mark = (SELECT MAX(Min_mark) from grades where min_mark <= students.marks)
case
when grade <8 then
order by grade desc, name asc
else
order by marks asc
end
但是由于语法错误,第二个查询没有执行。有人可以建议我如何获得所需的结果。提前致谢
我的猜测是这样的:
ORDER BY grade > 10 DESC /* orders by grade>10 records first */
, CASE WHEN grade > 10 THEN grade ELSE null END DESC /* all grade<=10 records will "sort" equally among themselves */
, CASE WHEN grade > 10 THEN name ELSE marks END ASC /* all grade<=10 records will "sort" by `name`, others will sort my `marks` */
我是一名优秀的程序员,十分优秀!