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


  • 相关阅读:
    git stash功能的使用
    git tag的应用
    git merge 与 git rebase的区别?
    git的一些操作命令
    docker的常用操作
    lvs搭建dr负载均衡集群
    centos8安装lvs
    centos8安装docker
    centos8用firewalld搭建防火墙
    openresty上安装waf
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9090692.html
Copyright © 2011-2022 走看看