此查询工作正常的MySQL,但不是在PostgreSQL的:查询工作正常的MySQL,但不是在PostgreSQL的
select
concat(hc.id, hl.languagecode) AS id,
hc.id AS category_id,
hl.languagecode AS languagecode
from language hl
join category hc
left join categorytranslation hct ON hl.languagecode = hct.languagecode and hc.id = hct.category_id;
在PostgreSQL有时我得到的错误:
ERROR: syntax error at end of input LINE 9: ....languagecode = hct.languagecode and hc.id = hct.category_id ^Query failed PostgreSQL said: syntax error at end of input
还是空的结果。 我正在使用Postico来测试它。
它有什么问题?
我想要做的就是让这样的结果:
select
concat(hc.id, hl.languagecode) AS id,
hc.id AS category_id,
hl.languagecode AS languagecode,
hc.slug AS slug
from category hc, language hl
但我也想加入与翻译“categorytranslation”的表。如果翻译是可用的而不是'类别'表格。为此,我修改了这样的查询:
SELECT
concat(hp.id, hl.languagecode) AS id,
hp.id AS id,
hl.languagecode AS languagecode,
hpt.languagecode as translang,
CASE WHEN (hpt.languagecode is not null and hpt.slug is not null and trim(hpt.slug) <> '')
THEN hpt.slug
ELSE hp.slug
END AS slug,
from language hl
join category hc
left join categorytranslation hct ON hl.languagecode = hct.languagecode and hc.id = hct.category_id;
连接条件看起来有点奇怪,因为你正在做的'language'和'category'表之间的交叉连接。它是否正确? –