我必须显示不在“时间表”表中的记录

时间:2018-07-02 06:59:28

标签: mysql

我必须显示不在“时间卡”表中的记录。该表包含以下列-

tcID Primary int(11)                    
RequestID int(11)           
StaffID int(11)             
ShiftStartDate date             
ShiftEndDate date               
JobStartTime time           
JobEndTime time         
lunchTaken time         
ApprovalCode varchar(45)    

查询:

SELECT *
FROM acceptedrequest ar
LEFT JOIN staff s ON s.StaffID = ar.StaffID
LEFT JOIN staffposition sp ON sp.PositionCode = s.PositionCode
WHERE
  ar.AgencyID = 0
  AND ar.RequestID = 2364
  and RepalceStatus = 0
  and ar.CancelStatus = 0
  and ar.BroadcastStatus = 0

1 个答案:

答案 0 :(得分:0)

请提供更多详细信息,例如:所有表信息及其关联方式。

如果我假设接受的请求人员不在考勤卡人员中, 尝试以下操作:

SELECT * FROM acceptedrequest ar
LEFT JOIN staff s ON s.StaffID = ar.StaffID  
LEFT JOIN staffposition sp ON sp.PositionCode = s.PositionCode 
WHERE ar.AgencyID = 0 
  AND ar.RequestID = 2364 
  AND RepalceStatus = 0 
  AND ar.CancelStatus = 0 
  AND ar.BroadcastStatus = 0  
  AND ar.staffID not in(SELECT staffID from timecard)

希望有帮助!