编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。

编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。_第1张图片

select ifnull((select distinct Salary from Employee order by Salary desc limit 1 offset 1),null)  as  SecondHighestSalary

//这题就考察了几个重要的函数
//ifnull(a,b)   如果a有值,就返回a--------如果a为空,则就返回b
//distinct c      去重函数,去掉c数据中重复的元素
//order by d      排序函数,将d的数据默认为升序排法
//desc            一般和order by  联合使用,order by 加上desc就是改变默认排序规则为降序
//as  E            为这个查询列起个别名为E

你可能感兴趣的:(mysql,sql)