我无法从外部查询所需的子查询中的表 b 中获取单个值。在表 b 中有一组与表 a 和表 c 相关的日期。在这里我需要最新日期的目的代码才能成功执行查询。如果我删除子查询并写 where c. purpose_code = b. purpose_code 它运行正常,但结果较旧。请帮帮我。
SELECT
a.filing_no AS "File No",
a.case_no AS "Registration No",
a.pet_name AS Petitioner,
a.res_name AS Accused,
a.dt_of_filing AS "Date of Inst",
max(b.Next_date) AS "Next Date",
c.purpose_name AS "Case Stage"
FROM
filing_t a, Daily_proc b, Purpose_t c
WHERE
a.filing_no = b.filing_no
AND c.purpose_code = (
SELECT purpose_code FROM Daily_proc
WHERE filing_no = a.filing_no AND next_date = max(next_date)
)
AND a.court_no = 1
AND a.ci_cri = 2
AND a.status = 'P'
GROUP BY
b.filing_no
ORDER BY
a.dt_of_filing DESC
LIMIT
0, 2000