设定:
(数量1)员工表(employeeID,employeeName)
(数量1)PayType表(payTypeID,payTypeName)
(数量1)PaySchedule表(payScheduleID,payScheduleName)
(数量1)交汇表(Employee_has_PayType),其中为员工分配了多种薪资类型(employeeID,payTypeID)
(数量1)交汇表(Employee_has_PaySchedule),其中为员工分配了多个薪资表(employeeID,payScheduleID)
我需要什么:
我想获得分配了一个或所有这些payTypeID(29,31,32)的所有EmployeeID(来自Employee_has_PayType) AND 具有payScheduleID 1的EmployeeID(来自Employee_has_PaySchedule)
我只想要那些符合这两个标准的EmployeeID。
到目前为止,我已经尝试过这个:
SELECT
Employee_has_PayType.Employee_employeeID as 'type',
Employee_has_PaySchedule.Employee_employeeID as 'sched'
FROM
Employee_has_PayType, Employee_has_PaySchedule
WHERE
Employee_has_PayType.PayType_payTypeID in (29,31,32)
AND
Employee_has_PaySchedule.PaySchedule_payScheduleID = 1
GROUP BY
Employee_has_PayrollSchedule.Employee_EmployeeID
但它只返回所有具有paySchedule 1的employeeID。
非常感谢任何帮助。
答案 0 :(得分:3)
尝试:
SELECT DISTINCT
Employee_has_PayType.Employee_employeeID
FROM Employee_has_PayType
JOIN Employee_has_PaySchedule
ON Employee_has_PayType.Employee_employeeID =
Employee_has_PaySchedule.Employee_employeeID
WHERE
Employee_has_PayType.PayType_payTypeID in (29,31,32)
AND Employee_has_PaySchedule.PaySchedule_payScheduleID = 1