我有一个这样的查询:
SELECT
jobs.*,
(
CASE
WHEN lead_informations.state IS NOT NULL THEN lead_informations.state
ELSE 'NEW'
END
) AS lead_state
FROM
jobs
LEFT JOIN lead_informations ON
lead_informations.job_id = jobs.id
AND
lead_informations.mechanic_id = 3
WHERE
lead_state = 'NEW'
这给出了以下错误:
PGError: ERROR: column "lead_state" does not exist
LINE 1: ...s.id AND lead_informations.mechanic_id = 3 WHERE (lead_state...
在 MySql 中这是有效的,但在 Postgresql 中显然不是。据我所知,原因是SELECT
查询部分的评估晚于WHERE
部分。这个问题有通用的解决方法吗?