我正在尝试提取上周首次轮班的工人清单。
现在,如果我将上周第一班的特定工作人员放在where子句(WHERE c.temp_nr ='XXXX'
)中,则我的SQL可以工作,但是当我删除该子句时,它只是超时
SELECT MIN(p.start_date), CONCAT(c.first_name, ' ', c.last_name) AS 'c.fullname', c.temp_nr
FROM contactstable c
LEFT JOIN projectlines p on c.temp_nr = p.candidate_number
WHERE c.temp_nr ='XXXX' and c.contact_type = 'Candidate'
HAVING MIN(p.start_date) between DATE_SUB( CURDATE( ) , INTERVAL (dayofweek(CURDATE())+6)
DAY )
AND DATE_SUB( CURDATE( ) , INTERVAL (dayofweek(CURDATE()))
DAY )
最佳答案
使用GROUP BY c.temp_nr
SELECT MIN(p.start_date), CONCAT(c.first_name, ' ', c.last_name) AS 'c.fullname', c.temp_nr
FROM contactstable c
LEFT JOIN projectlines p on c.temp_nr = p.candidate_number
WHERE c.contact_type = 'Candidate'
GROUP BY c.temp_nr
HAVING
MIN(p.start_date)
between
DATE_SUB(CURDATE(), INTERVAL (dayofweek(CURDATE())+6) DAY)
AND DATE_SUB(CURDATE() , INTERVAL (dayofweek(CURDATE())) DAY)
关于mysql - 上周创建 worker 表,进行第一次上类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56871279/