zoukankan      html  css  js  c++  java
  • 创建函数 与 调用 函数

    第N高的薪水 - LeetCode (中国) https://leetcode-cn.com/problems/nth-highest-salary/description/

    CREATE FUNCTION getNthHighestSalary (N INT) RETURNS INT
    BEGIN
    
    DECLARE dynamic_f VARCHAR (255);
    
    
    SET dynamic_f = CONCAT(
    	'getNthHighestSalary(',
    	N,
    	')'
    );
    
    
    SET N = N - 1;
    
    RETURN (
    	SELECT
    		CASE (
    			SELECT
    				COUNT(DISTINCT(Salary)) > N
    			FROM
    				Employee
    		)
    	WHEN 0 THEN
    		NULL
    	ELSE
    		(
    			SELECT DISTINCT
    				(Salary)
    			FROM
    				Employee
    			ORDER BY
    				Salary DESC
    			LIMIT N,
    			1
    		)
    	END AS dynamic_f
    );
    
    
    END
    

      

    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                    |
    +------------------------+


  • 相关阅读:
    2021 0309-1 准备工作
    课程总结
    第十四周课程总结&实验报告
    第十三周课程总结
    第十二周课程总结
    第十一周课程总结
    第十周课程总结
    2019春总结作业
    第十二周作业
    第十一周作业
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9090692.html
Copyright © 2011-2022 走看看