代码拉取完成,页面将自动刷新
# 177. 第N高的薪水
# https://leetcode-cn.com/problems/nth-highest-salary/
# 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');
DELIMITER $$;
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
# SET GLOBAL log_bin_trust_function_creators = 1;
READS SQL DATA
DETERMINISTIC
BEGIN
RETURN (
# Write your MySQL query statement below.
select
distinct e1.salary
from
Employee e1
where
(
select
count(distinct e2.salary)
from
Employee e2
where
e2.salary > e1.salary
) = N-1
);
END$$
DELIMITER ;$$
# clean-up
drop table Employee;
drop function getNthHighestSalary;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。