d2025422

目录

 一、182. 查找重复的电子邮箱 - 力扣(LeetCode)

 二、183. 从不订购的客户 - 力扣(LeetCode)

 三、184. 部门工资最高的员工 - 力扣(LeetCode)


一、182. 查找重复的电子邮箱 - 力扣(LeetCode)

采用分组,把邮件名称相同的放到一组 having统计这组的个数,个数大于1则证明这个电子邮件是重复的

select email as 'Email'
from person
group by email
having count(email) > 1

 二、183. 从不订购的客户 - 力扣(LeetCode)

一个顾客表

一个购买表

顾客表左连接购买表 保留左边的表

右边的列数据为空就可以表明没有购买过  

判断为null 可以使用ifnull  或者is  null

select c.name as 'Customers'
from Customers c
left join orders o on c.id = o.customerId
where ifnull(o.id,0) = 0 and ifnull(o.customerId,0) = 0;

 三、184. 部门工资最高的员工 - 力扣(LeetCode)

先用分组和max函数查出每个部门薪水的最大值是多少  因为知道了最大值以后就能把重复的数据保留下来,最大薪水的可能不仅仅只有一个人,而是多个人,但是知道了最大的薪水值就好办了

(select departmentId,max(salary) 
as 'salary' from Employee group by departmentId)

 这个中间结果和其他两个表在做连接,这里使用inner join 我试了普通的笛卡尔积是超时的

select d1.name as 'Department',e1.name as 'Employee',e1.salary as 'salary'
from (select departmentId,max(salary) as 'salary' from Employee group by departmentId) ee join Employee e1 on ee.departmentId = e1.departmentId and ee.salary = e1.salary
join Department d1 on e1.departmentId = d1.id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值