LeetCode.176 Second Highest Salary (Limit偏移量运用)
来源:互联网 发布:淘宝刷手会受什么处罚 编辑:程序博客网 时间:2024/06/05 11:05
题目:
Write a SQL query to get the second highest salary from the Employee
table.
+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+
For example, given the above Employee table, the query should return 200
as the second highest salary. If there is no second highest salary, then the query should return null
.
+---------------------+| SecondHighestSalary |+---------------------+| 200 |+---------------------+分析:
# Write your MySQL query statement below#给定工资表,查找工资第2的数据,如果不存在该数据,则返回null#先找出k个大的数据,之后在该批数据中查找最小的#防止只有一个数据的情况select max(emp.salary) as 'SecondHighestSalary'from(select salaryfrom employeegroup by salaryorder by salary desclimit 1,1) as emp;#科教篇 limit来表示偏移量,可以直接取第2大的数据# SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset; #limit start,OFFSET offset # 入门篇# SELECT * FROM table LIMIT 0,10;//检索记录行1-10 # 进阶篇# SELECT * FROM table LIMIT 2,10;//检索记录行3-13# SELECT * FROM table LIMIT 5,20;//检索记录行6-25 # 高级篇# SELECT* FROMtable LIMIT 5,-1;//检索记录行6到结尾数据# SELECT* FROMtable LIMIT 0,-1;//检索全部记录# SELECT * FROM table LIMIT 5; //检索前 5 个记录行
阅读全文
0 0
- LeetCode.176 Second Highest Salary (Limit偏移量运用)
- LeetCode:Second Highest Salary
- Leetcode: Second Highest Salary
- LeetCode Second Highest Salary
- Second Highest Salary Leetcode
- Leetcode: Second Highest Salary
- LeetCode Second Highest Salary
- 【Leetcode】 Second Highest Salary
- leetcode-Second Highest Salary
- 【LeetCode】Second Highest Salary && Nth Highest Salary
- LeetCode | Second Highest Salary & Nth highest salary
- LeetCode Database #176 Second Highest Salary
- 176 - Second Highest Salary
- Leetcode176. Second Highest Salary(MYSQL limit,offset 区别)
- 【leetcode SQL】Second Highest Salary
- [LeetCode][Database]Second Highest Salary
- 【leetcode】database Second Highest Salary
- Database LeetCode Second Highest Salary
- NodeJs的应用场景及实践
- 优化sql
- Fragment生命周期
- iOS Xcode 调试OpenGL shader 步骤详解
- Java连Mongodb出错的问题
- LeetCode.176 Second Highest Salary (Limit偏移量运用)
- LeetCode 173. Binary Search Tree Iterator
- 17.12.06,web学习第二十天,还有一年,努力吧青年商城增删改查记忆
- Learning Boost C++ Libraries.pdf 英文原版 免费下载
- 51nod1299 监狱逃离 最小割
- POJ 刷题系列:3299. Humidex
- Unity3d开发MOBA游戏类《王者荣耀》记录(一)
- 安卓开发(2):基本UI界面设计
- Find The Multiple-POJ-1426-BFS