我有一个带有子选择语句的查询,我正在寻找一种在 where 子句中使用它的方法,如下所示:
SELECT p.id as project_id, (
SELECT pfva.dateValue
FROM ProjectFieldValue pfva
WHERE (pfva.fieldKey = 'listing_date' AND p.id = project_id)
LIMIT 1
) as table_filter_date
FROM Project p
JOIN ProjectFieldValue pfv
ON p.id = pfv.project_id
WHERE (fieldKey = 'contract_status' AND pfv.textValue IN ('Active'))
AND table_filter_date BETWEEN '2020-06-06' AND '2020-12-12'
这似乎不起作用......
AND table_filter_date BETWEEN '2020-06-06' AND '2020-12-12'
我收到以下错误:
Unknown column 'table_filter_date' in 'where clause'
有什么方法可以在 HAVING 或 FIND_IN_SET 中或在 WHERE 中以某种方式使用此值“table_filter_date”。我基本上需要能够通过此变量以及开始日期和结束日期(使用 BETWEEN 和 AND)以某种方式过滤结果。
万千封印
慕莱坞森