首页 > 其他 > 详细

leetcode 刷题

时间:2018-10-21 14:39:30      阅读:153      评论:0      收藏:0      [点我收藏+]

176:第二高的薪水

技术分享图片

select (select distinct salary from employee order by salary limit 1 offset 1) as secondhighestsalary;  ---去掉第一个,再从第一个开始

 

177:第N高的薪水

技术分享图片

------相关子查询:子查询中引用了外层查询所引用表的字段
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN

  RETURN (
      # Write your MySQL query statement below.
    select max(salary) from employee e1
      where N=(select count(distinct salary) from employee e2
              where e2.salary >=e1.salary)
  );
END
----执行步骤,1.从父查询中取出每一条salary,与子查询中的e2.salary进行比较,直到当大于e2.salary的记录等于n
2.父查询输出最大的salary

https://blog.csdn.net/mascf/article/details/50288199 

178. 分数排名

技术分享图片

---相关子查询
---方法一
select
score,(select count(distinct score) from scores e1 where e1.score>= e2.score) rank from scores e2 order by rank;

 

leetcode 刷题

原文:https://www.cnblogs.com/papio/p/9824935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!