我有一个这样的查询:
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部分。有这个问题的常见解决方法吗?
MysqL的支持是,因为你体验到,非标准。正确的方法是重新打印在SELECT子句中使用的同一个表达式:
原文链接:https://www.f2er.com/postgresql/193509.htmlSELECT 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_informations.state IS NULL