SQL
现在有“课程表”,记录了学生选修课程的名称以及成绩。现在需要找出语文课中成绩第二高的学生成绩。如果不存在第二高成绩的学生,那么查询应返回 null。
答案1(limit a,b为取a,到b的数据),limit y offset x 分句表示查询结果跳过 x 条数据,读取前 y 条数据
select distinct 成绩 from 成绩表 where 课程='语文' order by 课程,成绩 desc limit 1,1;
答案2(ifnull(a,b),如果不是空,返回a,否则返回b)
select ifnull( (select max(distinct 成绩) from 成绩表 where 成绩<(select max(成绩) from 成绩表 where 课程='语文') and 课程='语文') ,null) as '语文课第二名成绩';