【面试必备】领扣SQL题解

【面试必备】领扣SQL题解_第1张图片

select name, population, area

from world

where area > 3000000 or population > 25000000;


 

【面试必备】领扣SQL题解_第2张图片

update  salary

set sex = char(ASCII(sex) ^ ASCII('m') ^ ASCII('f'));

 


 

【面试必备】领扣SQL题解_第3张图片

select * from cinema

where id % 2 = 1 and description != 'boring'

order by rating desc;


 

【面试必备】领扣SQL题解_第4张图片 

select class from courses

group by class

having count(distinct student) >= 5;


 

【面试必备】领扣SQL题解_第5张图片 

select Email from Person

group by Email

having count(distinct Id) >= 2;


 

【面试必备】领扣SQL题解_第6张图片 

delete p1

from Person p1, Person p2

where p1.Email = p2.Email and p1.Id > p2.Id


 

【面试必备】领扣SQL题解_第7张图片 

select p.FirstName, p.LastName, a.City, a.State

from Person p left join Address a on p.PersonId = a.PersonId;


 

【面试必备】领扣SQL题解_第8张图片 

SELECT b.Name AS Employee
FROM Employee a INNER JOIN Employee b
ON b.ManagerId IS NOT NULL AND b.ManagerId=a.Id AND b.Salary >a.Salary;


 

【面试必备】领扣SQL题解_第9张图片 

select b.Name as Customers from Customers b left join Orders a on b.Id = a.CustomerId where a.CustomerId is null; 


 

【面试必备】领扣SQL题解_第10张图片 

select d.Name as Department, e.Name as Employee, e.Salary from Department d, Employee e

(select DepartmentId, MAX(Salary) Salary from Employee group by DepartmentId) M

where e.DepartmentId = d.Id and e.DepartmentId = M.DepartmentId and e.Salary = M.Salary;

 


 

【面试必备】领扣SQL题解_第11张图片 

select

(select distinct Salary from Employee order by Salary desc limit 1,1)

SecondHighestSalary;


 

【面试必备】领扣SQL题解_第12张图片 

CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
  set N = N -1;
  RETURN (
      # Write your MySQL query statement below.      
      select 
      (Select distinct Salary from Employee order by Salary desc limit N,1)
  );
END


 

【面试必备】领扣SQL题解_第13张图片 

【面试必备】领扣SQL题解_第14张图片

 


【面试必备】领扣SQL题解_第15张图片 

【面试必备】领扣SQL题解_第16张图片


 

 

你可能感兴趣的:(JAVA面试必备)