181.超过经理收入的员工

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

+----+-------+--------+-----------+
| Id | Name  | Salary | ManagerId |
+----+-------+--------+-----------+
| 1  | Joe   | 70000  | 3         |
| 2  | Henry | 80000  | 4         |
| 3  | Sam   | 60000  | NULL      |
| 4  | Max   | 90000  | NULL      |
+----+-------+--------+-----------+
给定 Employee 表,编写一个 SQL 查询,该查询可以获取收入超过他们经理的员工的姓名。在上面的表格中,Joe 是唯一一个收入超过他的经理的员工。

+----------+
| Employee |
+----------+
| Joe      |
+----------+

答案:

select Name  from Employee a where a.Salary > (select Salary from Employee b where a.ManagerId=b.Id);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
employee.h: ```cpp #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { protected: int number; string name; int position; double monthBonus; double monthIncome; public: Employee(int number, string name, int position, double monthBonus); virtual ~Employee(); virtual void calculateMonthIncome() = 0; void showInfo(); }; #endif ``` employee.cpp: ```cpp #include "employee.h" #include <iostream> using namespace std; Employee::Employee(int number, string name, int position, double monthBonus) { this->number = number; this->name = name; this->position = position; this->monthBonus = monthBonus; this->monthIncome = 0; } Employee::~Employee() {} void Employee::showInfo() { cout << "编号:" << number << endl; cout << "姓名:" << name << endl; cout << "职务级别:" << position << endl; cout << "每月固定奖金:" << monthBonus << endl; cout << "每月月收入:" << monthIncome << endl; } ``` manager.h: ```cpp #ifndef MANAGER_H #define MANAGER_H #include "employee.h" class Manager : public Employee { public: Manager(int number, string name, int position, double monthBonus); ~Manager(); virtual void calculateMonthIncome(); }; #endif ``` manager.cpp: ```cpp #include "manager.h" Manager::Manager(int number, string name, int position, double monthBonus) : Employee(number, name, position, monthBonus) {} Manager::~Manager() {} void Manager::calculateMonthIncome() { monthIncome = 12000 * (3 - position + 1) / 3 + monthBonus + 3500; } ``` developer.h: ```cpp #ifndef DEVELOPER_H #define DEVELOPER_H #include "employee.h" class Developer : public Employee { private: int workHours; public: Developer(int number, string name, int position, double monthBonus, int workHours); ~Developer(); virtual void calculateMonthIncome(); }; #endif ``` developer.cpp: ```cpp #include "developer.h" Developer::Developer(int number, string name, int position, double monthBonus, int workHours) : Employee(number, name, position, monthBonus) { this->workHours = workHours; } Developer::~Developer() {} void Developer::calculateMonthIncome() { if (position == 1) { monthIncome = 6000 * (3 - position + 1) / 3 + monthBonus + workHours * 40 + 500; } else if (position == 2) { monthIncome = 6000 * (3 - position + 1) / 3 + monthBonus + workHours * 40; } else { monthIncome = 6000 * (3 - position + 1) / 3 + monthBonus; } } ``` main.cpp: ```cpp #include "employee.h" #include "manager.h" #include "developer.h" #include <iostream> using namespace std; int main() { Employee *e1 = new Manager(1001, "张三", 1, 5000); Employee *e2 = new Manager(1002, "李四", 2, 3000); Employee *e3 = new Developer(2001, "王五", 3, 2000, 80); Employee *e4 = new Developer(2002, "赵六", 1, 1000, 120); e1->calculateMonthIncome(); e2->calculateMonthIncome(); e3->calculateMonthIncome(); e4->calculateMonthIncome(); e1->showInfo(); e2->showInfo(); e3->showInfo(); e4->showInfo(); delete e1; delete e2; delete e3; delete e4; return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值