LeetCode 176. 第二高的薪水(MySQL版)
0.前言
最近刷LeetCode 刷数据库题目 由于数据库课上的是SQL,而MySQL有许多自己的函数的,怕把刚学会的函数忘记 特在此记录!
1.题目
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) 。 +----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
例如上述 Employee 表,SQL查询应该返回 200 作为第二高的薪水。如果不存在第二高的薪水,那么查询应返回 null。 +---------------------+
| SecondHighestSalary |
+---------------------+
| 200 |
+---------------------+
2.用到的知识点
limit : limit可以接收两个参数 limit 10 或者 limit 0,10
前者表示查询显示前10行
后者表示从第0行的往后10行,也就是第1行到第10行
IFNULL(expression_1,expression_2);
如果expression_1不为NULL 就显示自己,否则显示expression_2
类似Java expression1 != null? expression1:expression2
3.最终的SQL语句
select IFNULL
( (select distinct Salary from Employee order by Salary desc limit 1,1),(null) ) as SecondHighestSalary
LeetCode 176. 第二高的薪水(MySQL版)的更多相关文章
- SQL Server实现 LeetCode 176 第二高的薪水
176. 第二高的薪水 SQL架构 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+- ...
- LeetCode:176.第二高的薪水
题目链接:https://leetcode-cn.com/problems/second-highest-salary/ 题目 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Sal ...
- [Leetcode] 176.第二高薪水
题目: 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | ...
- MYSQL查询第二高的薪水
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+| Id | Salary |+----+--------+| 1 | 100 || ...
- Mysql训练:第二高的薪水(IFNULL,OFFSET,LIMIT)
编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 ...
- [SQL]LeetCode176. 第二高的薪水 | Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- MySql_176. 第二高的薪水 + limit + distinct + null
MySql_176. 第二高的薪水 LeetCode_MySql_176 题目描述 题解分析 代码实现 # Write your MySQL query statement below select( ...
- LeetCode176——第二高的薪水
题目描述 编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary) . +----+--------+ | Id | Salary | +----+--------+ | 1 ...
- LeetCode 176. Second Highest Salary (第二高的薪水)
题目标签: 题目给了我们一个工资表,让我们返回第二高的工资. 利用Max,把第一高的工资找到,然后利用 NOT IN,去找到第二高的工资. Java Solution: Runtime: 153ms ...
随机推荐
- 报错Domain=NSCocoaErrorDomain Code=3840 "Garbage at end."
网络请求出现报错:Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." 出现的问题是后台返回了两次json数据!
- 2018申请淘宝客AppKey
1.www.alimama.com 申请账号进入后2.进入我的联盟,按下面的步骤 完成以后等待网站审核. 3.审核完成后 按以下的图,申请进入开放平台或得appkey 4.最后就可以进入开放平台申请看 ...
- .NET Standard 2.0正式发布了
亦可赛艇 前天(2017年8月14日),.NET Standard 2.0正式版终于发布了,与之相配套的.NET Core 2.0也同时正式发布,真是令人振奋. 详情请看:https://blogs. ...
- C# 控制台应用程序中输出彩色字体
using System; class Example { public static void Main() { // Get a string array with the names of Co ...
- \r,\n,\r\n的区别和用法
https://blog.csdn.net/xiaofei2010/article/details/8458605
- [Swift]LeetCode228. 汇总区间 | Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...
- [Swift]LeetCode280. 摆动排序 $ Wiggle Sort
Given an unsorted array nums, reorder it in-place such that nums[0] <= nums[1] >= nums[2] < ...
- [Swift]LeetCode330. 按要求补齐数组 | Patching Array
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such th ...
- [Swift]LeetCode448. 找到所有数组中消失的数字 | Find All Numbers Disappeared in an Array
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- [Swift]LeetCode672. 灯泡开关 Ⅱ | Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After perform ...