是否可以使用别名作为 LIKE 搜索值?

Is it possible to use alias as LIKE Search value?

是否可以像这样使用 MySQL 别名作为搜索字符串?

SELECT
    af.id
FROM
    things af
LEFT JOIN
    questions AS aq
ON
    aq.id = 25
LEFT JOIN
    countries AS ff
ON
    ff.item_id = af.id
LEFT JOIN
    categories AS cc
ON
    cc.id = aq.catid
WHERE
    af.published = 1 AND af.cat_id IN(2, 3) AND ff.field_id = 8 AND ff.value LIKE '%cc.title%'

AND ff.value LIKE '%cc.title%'

MySQL 会将 '%cc.title%' 视为文字字符串,因此您的表达式不会执行您想要的操作。

相反,您可以使用 concat():

AND ff.value LIKE CONCAT('%', cc.title, '%')