当前位置:网站首页>力扣(LeetCode)177. 第N高的薪水(2022.06.26)
力扣(LeetCode)177. 第N高的薪水(2022.06.26)
2022-06-27 10:43:00 【ChaoYue_miku】
SQL架构:
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是该表的主键列。
该表的每一行都包含有关员工工资的信息。
编写一个SQL查询来报告 Employee 表中第 n 高的工资。如果没有第 n 个最高工资,查询应该报告为 null 。
查询结果格式如下所示。
示例 1:
输入:
Employee table:
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
±—±-------+
n = 2
输出:
±-----------------------+
| getNthHighestSalary(2) |
±-----------------------+
| 200 |
±-----------------------+
示例 2:
输入:
Employee 表:
±—±-------+
| id | salary |
±—±-------+
| 1 | 100 |
±—±-------+
n = 2
输出:
±-----------------------+
| getNthHighestSalary(2) |
±-----------------------+
| null |
±-----------------------+
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/nth-highest-salary
方法一:笛卡尔积
MySQL提交内容:
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
边栏推荐
- Deep learning in finance in cross sectional sectional predictions for random forests
- 【TcaplusDB知识库】TcaplusDB新增机型介绍
- Write it down once Net analysis of a property management background service stuck
- “全班29人24人成功读研”冲上热搜!剩下的5个人去哪了?
- 【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍
- [so official interview] Why do developers using rust love it so much
- oracle触发器 存储过程同时写入
- Feedforward feedback control system design (process control course design matlab/simulink)
- KDD 2022 | 基于分层图扩散学习的癫痫波预测
- 21:第三章:开发通行证服务:4:进一步完善【发送短信,接口】;(在【发送短信,接口】中,调用阿里云短信服务和redis服务;一种设计思想:BaseController;)
猜你喜欢

以后发现漏洞,禁止告诉中国!

Design and Simulation of direct torque control system for induction motor (motion control matlab/simulink)

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

【TcaplusDB知识库】TcaplusDB Tmonitor模块架构介绍

audiotrack与audioflinger

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

ci/cd自动化测试_CI / CD管道加快测试自动化的16种最佳实践
![leetcode:522. Longest special sequence II [greed + subsequence judgment]](/img/43/9b17e9cb5fee9d14c2986a2141889d.png)
leetcode:522. Longest special sequence II [greed + subsequence judgment]

C语言学习-Day_06

嵌入式软件架构设计-模块化
随机推荐
Cross cluster deployment of helm applications using karmada [cloud native open source]
Proe/Creo家电产品结构设计规范-电煎锅
Basic violin plot in R with plot
Red envelope rain: a wonderful encounter between redis and Lua
leetcode待做题目
Win10 shortcut key sorting
Design and Simulation of direct torque control system for induction motor (motion control matlab/simulink)
iMeta:高颜值绘图网站imageGP+视频教程合集,已被引360次(220625更新)
oracle触发器 存储过程同时写入
Installation manuelle de MySQL par UBUNTU
ci/cd自动化测试_CI / CD管道加快测试自动化的16种最佳实践
Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)
[tcapulusdb knowledge base] tcapulusdb Model Management Introduction
Feedforward feedback control system design (process control course design matlab/simulink)
Leetcode 729. 我的日程安排表 I(牛逼,已解决)
C language learning day_ 04
如何在 Methodot 中部署 JupyterLab?
使用Karmada实现Helm应用的跨集群部署【云原生开源】
[从零开始学习FPGA编程-47]:视野篇 - 第三代半导体技术现状与发展趋势
Mail system (based on SMTP protocol and POP3 protocol -c language implementation)