• [LeetCode]-DataBase-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 highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.

    需求:查询第N高的工资

    CREATE TABLE Employee(
    Id TINYINT UNSIGNED,
    Salary DECIMAL(10,2)
    )ENGINE=MyISAM CHARSET=utf8;


    -- sql 使用 limit 和 ORDER BY
    DROP FUNCTION IF EXISTS getNthHighestSalary;
    CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
    BEGIN
    DECLARE 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

  • 相关阅读:
    .net中Timer的使用
    计算日期的神器
    求全排列函数next_permutation
    各种排序
    求最大字段和
    炸弹时间复位
    最少步数,广搜
    数据
    水池数目
    最大岛屿
  • 原文地址:https://www.cnblogs.com/lianliang/p/5303069.html
Copyright © 2020-2023  润新知