ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

力扣数据库——第二高的薪水

力扣数据库——第二高的薪水

第二高的薪水https://leetcode.cn/problems/second-highest-salary/

一 题目

Employee表:

Column NameType
idint
salaryint
id 是这个表的主键。表的每一行包含员工的工资信息。

查询并返回Employee表中第二高的不同薪水 。如果不存在第二高的薪水,查询应该返回null(Pandas 则返回 None)

二 示例查询结果

示例 1:

输入:Employee 表: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+输出:+---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+

示例 2:

输入:Employee 表: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+输出:+---------------------+ | SecondHighestSalary | +---------------------+ | null | +---------------------+

三 结果

select( select distinct salary from Employee order by salary desc limit 1,1 --跳过前一条,取一条 ) as SecondHighestSalary
返回列表