我得到了下面的输出,我希望输出相同,但没有子查询
。我希望通过删除子查询来细化下面的查询,因为它会影响应用程序的性能。有人能帮助我删除子查询,并使用联接获取所需的数据吗?
SELECT DISTINCT rec.requestno as requestno
, (SELECT min(dateandtime)
from recruitersubmission
where recruitersubmission.requestno = rec.requestno) as firstsubmsion
, (SELECT max(dateandtime)
from recruitersubmission
where recruitersubmission.requestno = rec.requestno) as lastsubmission
, cndinterview.dateandtime as candidatefedtime
, cndinterview.dateandtime AS recruitertime
, CONCAT(availabledate,' ', availabletime) AS candidateavaibledatetime
, cndfeedback.status AS status
, cndfeedback.offereddate AS offereddate
, cnd.status AS onboard
, (SELECT COUNT(recruitersubmission.requestno)
FROM recruitersubmission
WHERE recruitersubmission.requestno=rec.requestno) AS totalSub
, (select COUNT(candidatefeedback.requestno)
from candidatefeedback
WHERE candidatefeedback.requestno = rec.requestno
&& candidatefeedback.status = 'Selected' ) as totalsel
, (select COUNT( candidatefeedback.requestno)
from candidatefeedback
WHERE candidatefeedback.requestno = rec.requestno
&& cndfeedback.status = 'Rejected' ) as totalrej
, (select COUNT(candidatefeedbkonboard.requestno)
from candidatefeedbkonboard
WHERE candidatefeedbkonboard.requestno = rec.requestno
&& cnd.status = 'Drop' ) as totaldrop
, (select COUNT(candidatefeedbkonboard.requestno)
from candidatefeedbkonboard
WHERE candidatefeedbkonboard.requestno = rec.requestno
&& candidatefeedbkonboard.status = 'Onboarded' ) as totalonboard
from recruitersubmission AS rec
LEFT JOIN candidatefeedbkonboard AS cnd
ON rec.requestno=cnd.requestno
LEFT JOIN candidatefeedback AS cndfeedback
ON rec.requestno=cndfeedback.requestno
LEFT JOIN candidatesinterview AS cndinterview
ON rec.requestno=cndinterview.requestno
where rec.clientname = '$client'
&& rec.requestno != ''
&& rec.country = '$location'
&& date(rec.dateandtime) between '$fromdate'
我想避免下面这些子查询。
(从候选人反馈WHERE候选人反馈.请求编号= rec.请求编号&&候选人反馈.状态= '已选择'中选择COUNT(候选人反馈.请求编号))作为总选择
2条答案
按热度按时间3j86kqsm1#
谢谢朋友们的帮助,我已经想好了怎么做,下面是解决方法,供大家参考。
ql3eal8s2#
回复:您的子查询:
(从招聘人员提交中选择min(日期与时间),其中招聘人员提交.请求编号= rec.请求编号)
需要
INDEX(requestno, dateandtime)
。其他子查询也是如此。回复:Seejith的回答:
可替换为
从而消除了对
COALESCE(.., 0)
的需要。