您好我有以下工作查询,但我希望摆脱子查询方法。
select t0.emp_id, t1.first_name, t1.last_name
from employee_profile As t0 left join user_profile as t1 on t0.user_profile_id = t1.id
where t0.emp_id not in (select t4.emp_id from time_sheet as t4 where t4.ts_end_date = '2014-10-08')
有1301个员工档案 结束日期2014-10-08有337没有time_sheets
到目前为止,这种方法非常有效。
现在我正在尝试从子查询迁移到连接中。我试过以下没有成功。
通过这个查询,我得到了与我正在寻找的完全相反的964结果。
select t0.emp_id, t1.first_name, t1.last_name, t3.emp_id
from employee_profile As t0 left join user_profile as t1 on t0.user_profile_id = t1.id
left join time_sheet as t3 on t0.id = t3.employee_profile_id
我还尝试了以下条件,使用条件得到0结果
1
where t3.ts_end_date = '2014-10-08'
and t3.employee_profile_id is null
2
where t3.ts_end_date = '2014-10-08'
and t3.id is null
有人知道如何解决这个问题吗?
答案 0 :(得分:1)
想出来
select t0.emp_id, t1.first_name, t1.last_name, t3.emp_id
from employee_profile As t0 left join user_profile as t1 on t0.user_profile_id = t1.id
left join time_sheet as t3 on t0.id = t3.employee_profile_id and t3.ts_end_date = '2014-10-08'
where t3.employee_profile_id is null