当前位置:网站首页>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
边栏推荐
- 【TcaplusDB知识库】Tmonitor系统升级介绍
- Oracle group statistics query
- [tcapulusdb knowledge base] Introduction to tmonitor background one click installation (I)
- 【值得收藏】Centos7 安装mysql完整操作命令
- 杰理之IO 口中断使用注意事项【篇】
- Future & CompletionService
- unity shadow 和outline组件动态加载出错解决方案、问题深入分析
- Go zero micro Service Practice Series (VII. How to optimize such a high demand)
- 力扣(LeetCode)177. 第N高的薪水(2022.06.26)
- go-zero微服务实战系列(七、请求量这么高该如何优化)
猜你喜欢
![[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)](/img/04/b1194ca3340b23a4fb2091d1b2a44d.png)
[tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (I)

【TcaplusDB知识库】TcaplusDB常规单据介绍

“互联网+”大赛命题火热对接中 | 一图读懂百度38道命题

How to deploy jupyterlab in methodot?

Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)

Oracle group statistics query

Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)

【TcaplusDB知识库】Tmonitor系统升级介绍

QStyle类用法总结(三)

NAACL 2022 | TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
随机推荐
Learning notes - data set generation
21: Chapter 3: develop pass service: 4: further improve [send SMS, interface]; (in [send SMS, interface], call Alibaba cloud SMS service and redis service; a design idea: basecontroller;)
隐私计算FATE-离线预测
Co jump
红包雨: Redis 和 Lua 的奇妙邂逅
杰理之DAC输出方式设置【篇】
File name setting causes an error to be written to writelines: oserror: [errno 22] invalid argument
Interview shock 60: what will cause MySQL index invalidation?
Privacy computing fat offline prediction
Redis 分布式锁15问,看看你都掌握了哪些?
Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)
【TcaplusDB知识库】Tmonitor后台一键安装介绍(一)
Oracle-多表查询
unity shadow 和outline组件动态加载出错解决方案、问题深入分析
政策关注 | 加快构建数据基础制度,维护国家数据安全
Dimitt's law
[tcapulusdb knowledge base] tcapulusdb tmonitor module architecture introduction
Change PIP mirror source
Oracle multi table query
一篇抄十篇,CVPR Oral被指大量抄袭