ifnull(a,b)函数解释:
如果value1不是空,结果返回a
如果value1是空,结果返回b
select ifnull(写好的sql,null);
select ifnull(
(select max(distinct 成绩) from 成绩表
where 成绩<(select max(成绩) from 成绩表 where 课程&#61;&#39;语文&#39;)
and 课程&#61;&#39;语文&#39;)
,null) as &#39;语文课第二名成绩&#39;;
- 用limit也可以&#xff0c;注意前面要用distinct.
select distinct 成绩
from 成绩表
where 课程&#61;&#39;语文&#39;
order by 课程,成绩 desc
limit 1,1;
查询第二高的工资&#xff1a;
select ifNull(
(select distinct salary
from Employee
order by Salary Desc
limit 1,1),null
) as SecondHighestSalary;