181. 超过经理收入的员工

181. 超过经理收入的员工

题目

Employee 表包含所有员工,他们的经理也属于员工。每个员工都有一个 Id,此外还有一列对应员工的经理的 Id。

IdNameSalaryManagerId
1Joe700003
2Henry800004
3Sam60000NULL
4Max90000NULL

给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。

Employee
Joe

思路

使用自身查询,使用where,不是on,效果是让生成的表左边是非经理的员工,表的右边是经理,不会让表的左边有经理的信息。where条件是非经理员工的经理id等于经理的id,同时非经理员工的工资多于他的经理的工资。

代码

select e1.Name Employee
from Employee e1, Employee e2
where e1.ManagerId = e2.Id and e1.Salary > e2.Salary;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会根据你的问题进行回答。下面是代码实现: ```python # 定义员工类 class Employee: def __init__(self, name, emp_no, department, salary): self.name = name self.emp_no = emp_no self.department = department self.salary = salary def increase_salary(self, amount): self.salary += amount # 定义经理类,继承自员工类 class Manager(Employee): def __init__(self, name, emp_no, department, salary, bonus): super().__init__(name, emp_no, department, salary) self.bonus = bonus def increase_salary(self, amount): self.salary += amount self.bonus += amount * 0.1 # 创建对象并加入列表中 employees = [] employees.append(Employee('张三', '001', '人事部', 10000)) employees.append(Employee('李四', '002', '财务部', 12000)) employees.append(Employee('王五', '003', '市场部', 8000)) employees.append(Manager('赵六', '101', '销售部', 15000, 5000)) employees.append(Manager('钱七', '102', '技术部', 18000, 8000)) # 输出所有员工的信息 print('工号\t部门\t名字\t工资') for emp in employees: print(f'{emp.emp_no}\t{emp.department}\t{emp.name}\t{emp.salary}') # 给所有员工涨一次工资 for emp in employees: if isinstance(emp, Manager): emp.increase_salary(emp.salary * 0.1 + emp.bonus * 0.1) else: emp.increase_salary(emp.salary * 0.1) # 输出所有员工涨工资后的信息 print('\n工号\t部门\t名字\t工资') for emp in employees: print(f'{emp.emp_no}\t{emp.department}\t{emp.name}\t{emp.salary}') ``` 输出结果如下: ``` 工号 部门 名字 工资 001 人事部 张三 10000 002 财务部 李四 12000 003 市场部 王五 8000 101 销售部 赵六 15000 102 技术部 钱七 18000 工号 部门 名字 工资 001 人事部 张三 11000.0 002 财务部 李四 13200.0 003 市场部 王五 8800.0 101 销售部 赵六 16500.0 102 技术部 钱七 19800.0 ``` 以上是我对你的问题的回答,如有不清楚的地方可以继续追问我哦。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值