在 mysql 中是否可以在连接字段上进行选择和搜索?
This is example: SELECT concat(members.name, " " ,members.surname) AS i FROM members where i LIKE '%string%'
您不能在 select 子句中为列加上别名,然后在 where 子句中使用它。
但是有很多方法可以做你想做的事情。
最接近的解决方案是使用HAVING
而不是WHERE
:
SELECT concat(members.name, " " ,members.surname) AS i
FROM members
HAVING i LIKE '%string%'
只需将 concat 添加到 WHERE
SELECT concat(members.name, " ", members.surname) as i FROM members WHERE concat(members.name, " ", members.surname) LIKE '%somestring%'
或者,像这样:
select * from
(SELECT concat(members.name, " " ,members.surname) AS i
FROM members) con
where con.i LIKE '%string%'
萨卢多斯 ;)