LeetCode 177 Nth-Highest Salary mysql,取第n条数据,limit子句 难度:1

https://leetcode.com/problems/nth-highest-salary/

ATTENTION:limit 子句只能接受int常量,不能接受运算式

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N = N - 1;
  RETURN (
      # Write your MySQL query statement below.
      select  DISTINCT Salary from Employee Order by  Salary DESC limit N,1
  );
END

  

时间: 2024-08-04 14:59:13

LeetCode 177 Nth-Highest Salary mysql,取第n条数据,limit子句 难度:1的相关文章

LeetCode-Algorithms #003 Longest Substring Without Repeating Characters, Database #177 Nth Highest Salary

LeetCode-Algorithms #003 Longest Substring Without Repeating Characters 对于给定的字符串, 找出其每个字符都不重复的子串中最长的那个, 并返回该子串的长度: 想法还是遍历: 1 class Solution { 2 public int lengthOfLongestSubstring(String s) { 3 // 如果s是null或空串, 就直接返回0 4 if (s == null || "".equals

mysql取前几行数据limit用法

mysql取前几行数据limit用法 order by id desc limit 10 按照id的倒序排序 取出前10条 order by id desc limit 0,10 按照id的倒序排序 取出前10条 order by id limit 5,10 按照id的正序排序 从第5条开始取10条

[LeetCode][SQL]Nth Highest Salary

Nth Highest Salary 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 highe

LeetCode:Nth Highest Salary - 第N高的工资

1.题目名称 Nth Highest Salary(第N高的工资) 2.题目地址 https://leetcode.com/problems/nth-highest-salary/ 3.题目内容 与这道题目相比,上一道题目"Second Highest Salary"是本题在N=2时的特例.两道题目的表结构完全一样,Employee表的结构如下: +----+--------+ | Id | Salary | +----+--------+ | 1  | 100    | | 2  |

177. Nth Highest Salary (Medium)

Source: https://leetcode.com/problems/nth-highest-salary/#/descriptionDescription: Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+----

LeetCode 176 Second Highest Salary mysql,select 嵌套 难度:1

https://leetcode.com/problems/second-highest-salary/ 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 th

177. Nth Highest Salary

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGINdeclare M int;set M = N-1;RETURN ( # Write your MySQL query statement below. select distinct salary from Employee order by salary desc limit M,1 );END 原文地址:https://www.cnblogs.com/ffeng0312/p

MySQL取上一条数据的某个字段值

SELECT @lagfield ,@lagfiled := targField, t.*FROM TABLE t, (SELECT @lagfield := '') r其中targField是你想要在下一行呈现的字段,根据字段是字符还是数字,最后的select 应该不同,如果是数字,则应该(select @lagfield:=0) r 创建自定义函数 CREATE FUNCTION lag(col_name VARCHAR(255))RETURNS VARCHAR(255) BEGIN DEC

[LeetCode] Nth Highest Salary 第N高薪水

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 =