LeetCode【更新中】
LeetCode中SQL题目
努力的SIR
你只管努力,其他的交给天意。
展开
-
Leetcode--SQL刷题(1194-1270)
1194. 锦标赛优胜者题目中有一个翻译错误,当得分相同时应该是id小的获胜。本题的关键是得到一个有player_id,group_id,score 组成的初始化表格。# 自己的方法:得到初始化表格,想想哪不对?select player_id,group_id, ifnull(m1.first_score,0)+ifnull(m2.second_score,0) scorefro...原创 2019-12-02 15:15:56 · 920 阅读 · 0 评论 -
Leetcode--SQL刷题(1149-1193)
1149. Article Views II# 0.33# 注意count()中应该是文章article的id,不能是count(*)会存在重复行。# 题目中问的也是 more than one articleselect distinct viewer_id id from viewsgroup by viewer_id,view_datehaving count(distin...原创 2019-11-28 10:42:27 · 700 阅读 · 0 评论 -
Leetcode--SQL刷题(1075-1148)
1075. 项目员工 I简单题目,重点注意小数点控制方法即可SELECT project_id, round(avg(experience_years),2) average_yearsFROM project p,employee eWHERE p.employee_id=e.employee_idGROUP by project_id...原创 2019-11-28 08:38:30 · 479 阅读 · 0 评论 -
Leetcode--SQL刷题(601-1070)
601.体育馆的人流量方法一:自己写的select id, visit_date, people from stadiumwhere id in(select distinct id from(select a.idfrom stadium a join stadium b on a.id=b.id+1join stadium c on b.id=c.id+1where a.pe...原创 2019-11-14 14:47:49 · 537 阅读 · 0 评论 -
Leetcode--SQL刷题(511-597)
512# 方法1 用于扩宽思路(都可以用变量做 但是简单题不见得更好)SELECT a.player_id, a.device_idFROM ( SELECT a.player_id, a.device_id , CASE WHEN @preCol = player_id THEN @rank := @rank + 1 ELSE @rank := 1 END AS...原创 2019-11-08 10:32:17 · 448 阅读 · 0 评论 -
Leetcode--SQL刷题(176-262)
# Write your MySQL query statement below答案一:常规思路select IFNULL((select distinct(Salary) from Employeeorder by Salary desclimit 1,1),null) as SecondHighestSalary;答案二:去掉最大值select max(Salary) Sec...原创 2019-10-17 15:48:39 · 1282 阅读 · 0 评论