当前位置:网站首页>Leetcode 177 The nth highest salary (June 26, 2022)
Leetcode 177 The nth highest salary (June 26, 2022)
2022-06-27 11:06:00 【ChaoYue_ miku】
SQL framework :
Create table If Not Exists Employee (Id int, Salary int)
Truncate table Employee
insert into Employee (id, salary) values ('1', '100')
insert into Employee (id, salary) values ('2', '200')
insert into Employee (id, salary) values ('3', '300')
±------------±-----+
| Column Name | Type |
±------------±-----+
| id | int |
| salary | int |
±------------±-----+
Id Is the primary key column of the table .
Each row of the table contains information about the employee's salary .
Write a SQL Query to report Employee No n High wages . If there is no n A maximum wage , The query should be reported as null .
The query result format is as follows .
Example 1:
Input :
Employee table:
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
±—±-------+
n = 2
Output :
±-----------------------+
| getNthHighestSalary(2) |
±-----------------------+
| 200 |
±-----------------------+
Example 2:
Input :
Employee surface :
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
±—±-------+
n = 2
Output :
±-----------------------+
| getNthHighestSalary(2) |
±-----------------------+
| null |
±-----------------------+
source : Power button (LeetCode)
link :https://leetcode.cn/problems/nth-highest-salary
Method 1 : The cartesian product
MySQL Submission :
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
# Write your MySQL query statement below.
SELECT
e1.salary
FROM
employee e1, employee e2
WHERE
e1.salary <= e2.salary
GROUP BY
e1.salary
HAVING
count(DISTINCT e2.salary) = N
);
END
边栏推荐
- Microsoft cloud technology overview
- What basic functions are required for live e-commerce application development? What is the future development prospect?
- 【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
- Ubuntu手动安装MySQL
- [tcapulusdb knowledge base] Introduction to tcapulusdb analytical text export
- 杰理之无缝循环播放【篇】
- Leetcode 522 longest special sequence ii[enumeration double pointer] leetcode path of heroding
- Memory compression for win10
- 政策关注 | 加快构建数据基础制度,维护国家数据安全
- 【TcaplusDB知识库】Tmonitor单机安装指引介绍(一)
猜你喜欢
![LeetCode 522 最长特殊序列II[枚举 双指针] HERODING的LeetCode之路](/img/b1/80a51b403dfb0611b87ef9aa3215af.png)
LeetCode 522 最长特殊序列II[枚举 双指针] HERODING的LeetCode之路

学习笔记之——数据集的生成

【TcaplusDB知识库】TcaplusDB单据受理-创建业务介绍

15+城市道路要素分割应用,用这一个分割模型就够了!

Ci/cd automatic test_ 16 best practices for CI / CD pipeline to accelerate test automation

Leetcode 729. 我的日程安排表 I(牛逼,已解决)

防止被00后整顿?一公司招聘要求员工不能起诉公司

【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)

红包雨: Redis 和 Lua 的奇妙邂逅
![[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)](/img/0a/3eae294b335c120c4aabd05e4230c3.png)
[tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
随机推荐
如何在 Methodot 中部署 JupyterLab?
3D mobile translate3d
Codeforces Round #786 (Div. 3) ABCDE
Proe/Creo家电产品结构设计规范-电煎锅
Future & CompletionService
【TcaplusDB知识库】TcaplusDB-tcaplusadmin工具介绍
Co jump
Queue, two-way queue, and its application
Oracle-分组统计查询
力扣(LeetCode)177. 第N高的薪水(2022.06.26)
deep learning statistical arbitrage
杰理之睡眠以后定时唤醒系统继续跑不复位【篇】
.NET6接入Skywalking链路追踪完整流程
File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument
LeetCode 522 最长特殊序列II[枚举 双指针] HERODING的LeetCode之路
堆-堆排序-TopK
【TcaplusDB知识库】TcaplusDB单据受理-事务执行介绍
Codeforces Round #786 (Div. 3) ABCDE
KDD 2022 | epileptic wave prediction based on hierarchical graph diffusion learning
杰理之一直喂狗会频繁开关中断导致定时器【篇】