我需要有关转换查询的帮助,如何将带有join的查询重写为带有子查询的查询。原始查询和转换查询都应返回相同的结果。我只需要查看它们在自动跟踪方面的差异并解释计划。谢谢。
select emp.employee_id, count(jh.department_id) as ID_Count
from employees emp left outer join
job_history jh
on emp.employee_id = jh.employee_id
group by emp.employee_id;
答案 0 :(得分:2)
您可以使用以下代码:
select emp.employee_id,
(select count(jh.department_id)
from job_history jh
where emp.employee_id = jh.employee_id
) as ID_Count
from employees emp;
希望我能帮上忙!