CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGIN RETURN ( # Write your MySQL query statement below. );END 1. 参考1: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INTBEGINDECLARE M INT;SET M=N-1; RETURN ( # Write your MySQL query statement below. SELECT DISTINCT Salary FRO...
Write a SQL query to get thenth highest salary from theEmployeetable. +---+---+ | Id | Salary | +---+---+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +---+---+ For example, given the above Employee table, thenth highest salary wheren= 2 is200. If there is nonth hig...
而题目一般期望当没有值时,返回一个null,于是需要套个SELECT ([expression]) AS Salary这样的壳,所以最后结果是这样的: CREATEFUNCTIONgetNthHighestSalary(NINT)RETURNSINTBEGINDECLAREMINT;SETM=N-1;RETURN(# Write your MySQL query statement below.SELECT(SELECTDISTINCTSalaryFROMEmployeeORDERBYSalaryDESCLIMIT1OFFSE...
1CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT2BEGIN3setN = N-1;4RETURN (5# Write your MySQL query statement below.6selectdistinct SalaryfromEmployee order by Salary desc limit N,17);8END 149ms 1CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT2BEGIN3setN = N-1;4RETURN ...
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 2. Alternate Solution This is another solution to find Nth highest...
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT /* 设定n*/ 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
46. Write a query to get employees older than 35 and working in the operation department. SELECT * FROM Intellipaat_Emp WHERE age > 35 AND department = 'operation'; 47. Write a query to find the average salary for each department. SELECT department, AVG(salary) AS avg_salary FROM Inte...
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN declare m INT; set m=N-1; RETURN ( # Write your MySQL query statement below. ifnull(( select salary from Employee order by salary desc limit m,1),null) ); END 3.用户行为数据分析-登录/留存 数据库中存在login_user表,结构如下...
177. Nth Highest Salary Write a SQL query to get thenth highest salaryfrom theEmployeetable. 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. ...
Finding record of Nth highest salaried employee (where N, should equal to records or less then of the records), Here we are finding 1st , 2nd, 3rd and so on highest salaried employee’s name one by one using SQL Query. Here employee table, which has three fields eid(employee id), ...