今天做的力扣SQL
我本地markdown的东西直接复制出来了。
多说一嘴,今天早上六点醒了,然后被外面吵,心里也担心找实习就一直睡不着了。索性直接来实验室,这一上午感觉好快啊。幸运的是,自己也没有浪费时间,还行吧。SQL欠的账迟早要还
181-employees-earning-more-than-their-managers
找出收入比经理高的员工
select a.name as 'Employee'
from employee as a, employee as b
where a.managerId = b.id and a.salary > b.salary
182-duplicate-emails
编写解决方案来报告所有重复的电子邮件。 请注意,可以保证电子邮件字段不为 NULL。
以 任意顺序 返回结果表。
查找重复的电子邮箱
select email
from Person
group by email
having count(email) > 1
183-customers-who-never-order
https://leetcode.com/problems/customers-who-never-order/description/
找出所有从不点任何东西的顾客。
从不订购的客户,2025年6月9日 星期一
select customers.name as 'Customers'
from customers
where Customers.id not in (select customerId from orders)-- left join
select customers.name as 'Customers'
from customers
left join orders on Customers.id = Orders.customerId
where Orders.customerId is null
184-department-highest-salary
查找出每个部门中薪资最高的员工。
按 任意顺序 返回结果表。
https://leetcode.com/problems/department-highest-salary/description/
部门工资最高的员工
select Department.name as 'Department',Employee.name as 'Employee',Employee.salary as 'Salary'
from Employee
left join Department on Employee.departmentId = Department.id
where (Department.id, salary) in (select departmentId, max(salary)from Employeegroup by departmentId)