我需要您的帮助才能获得两个查询的结果并将其显示为一个。我需要显示记录:
员工姓名,工资,储蓄金额,扣除金额
员工姓名和薪水存储在名为"员工"的表中。并且保存金额存储在名为" Saving"的表中。并且扣除金额存储在"扣除"表。在每个表中,"员工代码"是主键。
第一个查询是:
select e.employee_name, e.salary, s.saving_amount
from Employee e, Saving s
where e.employee_code = s.employee_code
and saving_amount > 1000
第二个问题是:
select e.employee_name, d.deduction_amount
from Employee e, deduction d
where e.employee_code = d.employee_code
并非所有员工都有扣款,也不是所有员工都有储蓄。
现在我需要显示结果:
员工姓名,工资,储蓄金额,扣除金额
AAA 1000 2000 500
BBB 5000
CCC 3000 1500
答案 0 :(得分:0)
这将帮助您入门。您可以填写详细信息。
from employee e left join savings s on e..employee_code = s.employee_code
and saving_amount > 1000
left join deduction d on e.employee_code = d.employee_code
这也假设并非所有员工都有储蓄。
答案 1 :(得分:0)
并非所有员工都有扣款,也不是所有员工都有储蓄。如果你想要这个查询就行了。
SELECT Employee.employee_name, Saving.savings_amount, Deduction.employee_deduction, Employee.employee_salaray
FROM Employee LEFT OUTER JOIN 在Employee.employee_code = Deduction.employee_code FULL OUTER JOIN上扣除 保存ON Employee.employee_code = Saving.employee_code --WHERE(Saving.savings_amount> 1000)
这会产生这样的结果: employee_name savings_amount employee_deduction employee_salaray
AAA 2000.00 500.00 1000.00 BBB 0.00 NULL 5000.00 CCC 1500.00 NULL 3000.00