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 ...
随机推荐
- webpack配置非CMD规范的模块
一.前言 webpack在配置多页面开发的时候 ,发现用 import 导入 Zepto 时,会报 Uncaught TypeError: Cannot read property 'createEl ...
- node.js搭建Web服务器
Node.js 博客搭建 一. 学习需求 Node 的安装运行 会安装node,搭建node环境 会运行node. 基础模块的使用 Buffer:二进制数据处理模块 Event:事件模块 fs:文件系 ...
- 关于使用freemarker导出文档的使用
7.FreeMarker导出word文件,模板:template.ftl/** * 为word加载数据插值 * * @throws IOException */ public void exportW ...
- ABP入门系列(3)——领域层定义仓储并实现
ABP入门系列目录--学习Abp框架之实操演练 一.先来介绍下仓储 仓储(Repository): 仓储用来操作数据库进行数据存取.仓储接口在领域层定义,而仓储的实现类应该写在基础设施层. 在ABP中 ...
- [Swift]LeetCode152. 乘积最大子序列 | Maximum Product Subarray
Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...
- [Swift]LeetCode337. 打家劫舍 III | House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this a ...
- [Swift]LeetCode529. 扫雷游戏 | Minesweeper
Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representin ...
- 在龙芯小本上安装Debain8.10
(图片是LEMOTE8089D笔记本,来自互联网) YX原来送了一个LEMOTE笔记本给我.CPU是首款真正的国产,龙芯2F,兼容mips的指令集. 笔记本原来的操作系统是Debian6,后来升级到了 ...
- 【ASP.NET Core快速入门】(十三)Individual authentication 模板、EF Core Migration
Individual authentication 模板 我们首先用VSCode新建一个mvc的网站,这个网站创立的时候回自动为我们创建Identuty Core以及EF Core的代码示例,我们可以 ...
- leetcode — binary-tree-zigzag-level-order-traversal
import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://o ...