【面试必备】领扣SQL题解

select name, population, area

from world

where area > 3000000 or population > 25000000;


 

update  salary

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

 


 

select * from cinema

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

order by rating desc;


 

 

select class from courses

group by class

having count(distinct student) >= 5;


 

 

select Email from Person

group by Email

having count(distinct Id) >= 2;


 

 

delete p1

from Person p1, Person p2

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


 

 

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

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


 

 

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;


 

 

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


 

 

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;

 


 

 

select

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

SecondHighestSalary;


 

 

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


 

 

 


 


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值