力扣MYSQL练习
176编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。
select IFNULL((SELECT distinct salary
from employee
order by salary desc
limit 1,1),NULL)AS SECONDHIGHESTSALARY;
select max(salary) as SecondHighestSalary
from employee
where salary not in (select max(salary) from employee);
178编写一个 SQL 查询来实现分数排名。如果两个分数相同,则两个分数排名(Rank)相同。请注意,平分后的下一个名次应该是下一个连续的整数值。换句话说,名次之间不应该有“间隔”。
别人的解法,先去重,再count,这样效率好很多,,我那解法巨慢。
select Score,
(select count(*) from(select distinct Score s from Scores) temp where s>=Score) as Rank
from Scores
order by Score desc
进击的小🐴农