leetcode数据库题目及答案汇总

1、 第二高的薪水
select ifnull((select distinct Salary from Employee order by Salary desc limit 1,1),null) as SecondHighestSalary;
 
2、第N高的薪水
select distinct Salary from Employee e where N = (select count(distinct Salary) from Employee where Salary >= e.Salary );
 
3、分数排名
  select Score,(select count(distinct score) from Scores where score >= s.score) as Rank from Scores as s order by Score desc;
 
4、超过经理收入的员工
  select e1.Name as Employee from Employee as e1,Employee as e2 where e1.ManagerId=e2.Id and e1.Salary>e2.Salary;
 
5、 查找重复的电子邮箱
select Email from Person group by Email having count(Email)>1;
 
6、从不订购的客户
select c.Name as Customers from Customers as c left join Orders as o on c.Id = o.CustomerId where c.Id not in (select c.Id from Customers as c,Orders as o where c.Id = o.CustomerId);
 
7、部门工资最高的员工
    select d.Name as Department,e.Name as Employee,e.Salary from Department as d inner join Employee as e on d.Id = e.DepartmentId and e.Salary>=(select max(Salary) from Employee where DepartmentId=d.Id);
 
8、删除重复的电子邮箱
   delete p1.* from Person p1,Person p2 where p1.Email=p2.Email and p1.id>p2.id;
 
9、上升的温度
  select w1.Id from Weather w1 join Weather w2 on DATEDIFF(w1.RecordDate, w2.RecordDate) = 1 where w1.Temperature>w2.Temperature;
 
10、交换性别
update salary set
sex = case sex
when 'm' then 'f'
else 'm'
end;

转载于:https://www.cnblogs.com/chaofan-/p/10412273.html

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值