
SQL
棱镜7
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode:608 树节点
文章目录一、code1.1 题目描述1.2 题解二、总结一、code1.1 题目描述地址1.2 题解# Write your MySQL query statement belowselect id, case when p_id is null then 'Root' when id in (select distinct p_id from tree) then 'Inner' # 当not in() 里面包含null值,查询不会返回任何值原创 2022-05-29 15:42:44 · 1203 阅读 · 0 评论 -
Leetcode:262 行程和用户
文章目录一、code1.1 题目描述1.2 题解二、总结一、code1.1 题目描述Leetcode地址1.2 题解# Write your MySQL query statement belowselect a.request_at 'Day',round(sum(if(a.status = 'completed',0,1))/count(*), 2) 'Cancellation Rate'from ( select request_at, s原创 2022-05-25 18:31:48 · 95 阅读 · 0 评论 -
Leetcode:185 部门工资前三高的所有员工
文章目录一、code1.1 题目描述1.2 题解二、总结一、code1.1 题目描述Leetcode地址1.2 题解select dep.name Department, a.name Employee, a.salary Salaryfrom Department dep join (select departmentId, name, salary, dense_rank() over(partition by depa原创 2022-05-24 13:31:35 · 925 阅读 · 0 评论 -
Leetcode:180 连续出现的数字
文章目录一、code1.1 题目描述1.2 题解二、总结一、code1.1 题目描述Leetcode地址1.2 题解select distinct # 去重 l1.num as ConsecutiveNumsfrom Logs l1, Logs l2, Logs l3where l1.id + 1 = l2.id # 连续三个 and l2.id = l3.id - 1 and l1.num = l2.num # 值相同原创 2022-05-21 16:12:14 · 230 阅读 · 0 评论 -
Leetcode:178 分数排名
文章目录一、code二、知识点rank函数一、codeLeetcode:178 分数排名# Write your MySQL query statement belowselect score, dense_rank() over(order by score desc) as 'rank' # 这个rank之所以要加引号,因为rank本身是个函数,直接写rank会报错from Scores;二、知识点rank函数rank(): 对查询数据进行排序,值相同的排序后序号也会相同,注意r原创 2022-05-19 10:22:29 · 136 阅读 · 0 评论 -
Leetcode:177 第N高的薪水
文章目录一、code一、codeLeetcode:177 第N高的薪水CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGIN declare m INT; SET M = N - 1; RETURN ( # Write your MySQL query statement below. select ifnull((select distinct salary as getNth原创 2022-05-19 09:31:49 · 118 阅读 · 0 评论 -
Leetcode176:第二高的薪水
文章目录一、code二、知识点1.ifnull2.limit与offset用法一、codeselect ifnull((select distinct salary from employee order by salary desc limit 1 offset 1), null) as SecondHighestSalary;二、知识点1.ifnullifnull() 函数用于判断第一个表达式是否为NULL,如果为NULL则返回第二个原创 2022-05-18 11:45:21 · 143 阅读 · 0 评论