当前位置:网站首页>【无标题】
【无标题】
2022-07-26 08:53:00 【小唐学姐】
SQL架构
Employee
表:
+-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id 是这个表的主键。 表的每一行包含员工的工资信息。
编写一个 SQL 查询,获取并返回 Employee
表中第二高的薪水 。如果不存在第二高的薪水,查询应该返回 null
。
查询结果如下例所示。
示例 1:
输入: Employee 表: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ 输出: +---------------------+ | SecondHighestSalary | +---------------------+ | 200 | +---------------------+
示例 2:
输入: Employee 表: +----+--------+ | id | salary | +----+--------+ | 1 | 100 | +----+--------+ 输出: +---------------------+ | SecondHighestSalary | +---------------------+ | null | +---------------------+
SELECT
IFNULL(
(SELECT DISTINCT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT 1 OFFSET 1),
NULL) AS SecondHighestSalary
边栏推荐
猜你喜欢
随机推荐
The idea shortcut key ALT realizes the whole column operation
Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)
The effective condition of MySQL joint index and the invalid condition of index
unity TopDown角色移动控制
C # use npoi to operate Excel
Form form
Human computer interaction software based on C language
Web overview and b/s architecture
pl/sql之动态sql与异常
数据库操作 题目二
[recommended collection] MySQL 30000 word essence summary + 100 interview questions (I)
Uploading pictures on Alibaba cloud OSS
PAT 甲级 A1013 Battle Over Cities
PAT 甲级 A1034 Head of a Gang
Database operation skills 7
12306 ticket system crawling - 1. Saving and reading of city code data
Database operation topic 1
Solve the problem of C # calling form controls across threads
Cve-2021-3156 duplicate of sudo heap overflow privilege raising vulnerability
SSH,NFS,FTP