业务场景需求,需要查询出某个招聘岗位投递简历人员数量(要求:将已投递该岗位,但是此人在数据库中已经不存在的人员过滤掉不做统)
select a.*,count(temp.apply_id) as apply_number
from info_request a
LEFT JOIN (select b.* from people_apply_record bjoin people_baseinfo c on c.people_id=b.people_id and c.in_user=1where b.in_use=1) temp on a.id=temp.job_id and temp.in_use=1
where a.in_use=1
and a.enterprise_id=:enterprise_id
GROUP BY a.id;
优化后代码块,省去子查询,提高代码执行效率。
select a.*,count(c.people_id) as apply_number
from info_request a
LEFT JOIN people_apply_record b on a.id=b.job_id and b.in_use=1
LEFT JOIN people_baseinfo c on c.people_id=b.people_id and c.in_user=1 and b.apply_id is not null
where a.in_use=1
and a.enterprise_id=:enterprise_id
BY a.id;