我有一个查询。在此查询中,我使用子查询从具有不同条件的同一个表中获取数据,在主查询中,我提到了用于在子查询中获取数据的 id,并设置了一个条件,即正在存在的值在主查询中考虑的 id 不应为空。如果我在主查询中使用带有 IN 子句的单个 ID,我的查询工作正常,但如果我在主查询中使用多个 id 并添加值不应为空的子句,则查询不会给我想要的结果。这是我的查询
SELECT e.id AS `Personal Number`,
e.date AS `Date`,
CONCAT(ep.firstname,' ',ep.lastname) AS `Employee Name`,
IF(ep.sex='M','Male','Female') AS sex,
DATE_FORMAT(p.birthdate,'%m/%d/%Y')AS birthdate,
(SELECT `value` FROM employee_data WHERE history=87 AND DATE=e.date) AS `A`,
(SELECT `value` FROM employee_data WHERE history=603 AND DATE=e.date) AS `B`,
(SELECT `value` FROM employee_data WHERE history=82 AND DATE=e.date) AS `C`,
(SELECT `value` FROM employee_data WHERE history=86 AND DATE=e.date) AS `D`
FROM tbl e
INNER JOIN employee ep ON e.id = ep.id
INNER JOIN tbl2 ap ON ap.date=e.date
INNER JOIN employee_data AS phd ON e.date = phd.date
WHERE (phd.history IN(82,87,603,86) AND phd.value!='') AND ap.date BETWEEN '2013-01-01' AND '2013-09-01'AND e.status!='cancelled'.
我不知道如何处理这个查询。任何人都可以帮忙。提前致谢