2 回答
TA贡献1891条经验 获得超3个赞
您可以通过将查询包含为“表表达式”来生成此命名列。例如:
select *
from ( -- table expression "x" starts
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'))
) x -- table expression "x" ends
WHERE table_filter_date BETWEEN '2020-06-06' AND '2020-12-12'
TA贡献1810条经验 获得超4个赞
存储table_filter_date在变量中并在您的WHERE子句中使用它:
SELECT p.id as project_id, ( @tfd := (
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 @tfd BETWEEN '2020-06-06' AND '2020-12-12'
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报