LeetCode 177. Nth Highest Salary
https://leetcode.com/problems/nth-highest-salary/description/
Write a SQL query to get the nth highest salary from the Employee
table.
+----+--------+
| Id | Salary |
+----+--------+
| 1 | 100 |
| 2 | 200 |
| 3 | 300 |
+----+--------+
For example, given the above Employee table, the nth highest salary where n = 2 is 200
. If there is no nth highest salary, then the query should return null
.
+------------------------+
| getNthHighestSalary(2) |
+------------------------+
| 200 |
+------------------------+
Create table If Not Exists Employee (Id int, Salary int);
Truncate table Employee;
insert into Employee (Id, Salary) values ('', '');
insert into Employee (Id, Salary) values ('', '');
insert into Employee (Id, Salary) values ('', ''); CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT;
SET M = N - 1;
RETURN (
# Write your MySQL query statement below.
SELECT
(SELECT Salary
FROM Employee
ORDER BY Salary DESC
LIMIT M, 1) AS getNthHighestSalary
);
END
LeetCode 177. Nth Highest Salary的更多相关文章
- 【SQL】177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- leetcode - database - 177. Nth Highest Salary (Oracle)
题目链接:https://leetcode.com/problems/nth-highest-salary/description/ 题意:查询出表中工资第N高的值 思路: 1.先按照工资从高到低排序 ...
- 177. Nth Highest Salary
问题描述 解决方案 CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare number int; set numbe ...
- [LeetCode] Nth Highest Salary 第N高薪水
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- leetcode Database3(Nth Highest Salary<—>Consecutive Numbers<—>Department Highest Salary)
一.Nth Highest Salary Write a SQL query to get the nth highest salary from the Employee table. +----+ ...
- LeetCode——Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- find the Nth highest salary(寻找第N高薪水)
Suppose that you are given the following simple database table called Employee that has 2 columns na ...
- [SQL]LeetCode177. 第N高的薪水 | Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
- LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1
https://leetcode.com/problems/second-highest-salary/ Write a SQL query to get the second highest sal ...
随机推荐
- IDEA 搭建授权服务器
引用地址 http://blog.lanyus.com/archives/317.html 今天突出发现基本公开的激活地址都被屏蔽了(IDEA 2017.3 版本) 记录一下 docker pull ...
- UOJ #266 【清华集训2016】 Alice和Bob又在玩游戏
题目链接:Alice和Bob又在玩游戏 这道题就是一个很显然的公平游戏. 首先\(O(n^2)\)的算法非常好写.暴力枚举每个后继计算\(mex\)即可.注意计算后继的时候可以直接从父亲转移过来,没必 ...
- Codeforces Round #381 (Div. 2) D. Alyona and a tree dfs序+树状数组
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 菜单项onCreateOptionsMenu()和onOptionsItemSelected()的使用
Java源文件 package com.example.macname.myapplication; import android.support.v7.app.AppCompatActivity; ...
- 利用JS将页面中包含“一个”字段值的元素改为红色
document.body.innerHTML = document.body.innerHTML.replace(/一个/ig,"<span style='color: red;'& ...
- window下rabbitmq环境安装
最近项目想用个MQ来做业务分离,看了市面上众多产品,最后选了rabbitmq,理由很简单,对window的支持很到位(其实是公司的系列产品都是.net的). 安装方法什么的就不说了,直接到官网下载双击 ...
- 剑指 offer面试题22 栈的压入和弹出序列
题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序 ...
- JS BOM操作
Bom:浏览器对象模型(Browser Object Model,简称 BOM)提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口,可以对浏览器窗口进行访问和操作 (1) ...
- 关于将vector以及string传递给较老的api的问题
现在可能STL使用的越来越多,但是一些较老的api并不支持例如vector这样的兑现,但是可以使用一些技巧来使其适应于这些函数. 例如对于使用到int*型的函数来说,传入一个 &vector[ ...
- Hadoop/Spark入门学习笔记(完结)
Hadoop基础及演练 ---第1章 初识大数据 大数据是一个概念也是一门技术,是在以Hadoop为代表的大数据平台框架上进行各种数据分析的技术. ---第2章 Hadoop核心HDFS Hadoop ...