Leetcode sql 알고리즘 문제

954 단어 sql알고리즘
주로 4 화 블 로 그 를 참고 합 니 다.
http://www.raychase.net/2810
--175  Combine Two Tables
--   
select p.FirstName, p.LastName, a.City, a.State
  from Person p
  left outer join Address a
    on p.PersonId = a.PersonId;

--176 Second Highest Salary
--        max            
select MAX(Salary)
  from (SELECT Salary
          from Employee
         where Salary < (select MAX(Salary) from Employee ));
--    mysql    desc limit( m,n)  m  , n       0
select IFNULL((select e.Salary
                from Employee e
               group by e.Salary
               order by e.Salary desc limit 1, 1),
              NULL) SecondHighestSalary;
              
--177	Nth Highest Salary
--   N         function 
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

좋은 웹페이지 즐겨찾기