3个月用python刷完leetcode600题!-数据库中等题
2017-07-02 本文已影响99人
文哥的学习日记
算法刷多了,感觉脑子里全是浆糊了,所以做一做数据库的题调整一下,哈哈哈哈!
177. Nth Highest Salary
177. Nth Highest Salarylimit的第一个数的意思是跳过多少记录,第二个数的意思是取多少条记录。不知道这里limit N-1 为何不行。
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
Declare M INT;
set M=N-1;
RETURN (
# Write your MySQL query statement below.
select distinct Salary from Employee order by Salary desc limit M,1
);
END
178. Rank Scores
178. Rank Scoresselect Score,(select count(distinct Score) from Scores where Score >= s.Score) as Rank from Scores as s order by Score desc
180. Consecutive Numbers
180. Consecutive Numbers三表内链接:
select distinct l1.Num as ConsecutiveNums from Logs as l1,Logs as l2,Logs as l3 where l1.Id + 1 = l2.Id and l2.Id+1 = l3.Id and l1.Num = l2.Num and l2.Num = l3.Num
如果你喜欢我写的文章,可以帮忙给小编点个赞或者加个关注,我一定会互粉的!
如果大家对leetcode感兴趣,欢迎跟小编进行交流,小编微信为sxw2251,加我要写好备注哟!:
我的微信