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