Answers:
您提供的别名用于查询的输出-它们本身在查询中不可用。
您可以重复表达:
SELECT neededfield, CONCAT(firstname, ' ', lastname) as firstlast
FROM users
WHERE CONCAT(firstname, ' ', lastname) = "Bob Michael Jones"
或包装查询
SELECT * FROM (
SELECT neededfield, CONCAT(firstname, ' ', lastname) as firstlast
FROM users) base
WHERE firstLast = "Bob Michael Jones"
使用CONCAT_WS()。
SELECT CONCAT_WS(' ',firstname,lastname) as firstlast FROM users
WHERE firstlast = "Bob Michael Jones";
第一个参数是其余参数的分隔符。
CONCAT_WS(' ', ..
有重复CONCAT
表达式或使用子查询的替代方法。您可以使用该HAVING
子句来识别列别名。
SELECT
neededfield, CONCAT(firstname, ' ', lastname) AS firstlast
FROM
users
HAVING firstlast = "Bob Michael Jones"
这是一个有效的SQL Fiddle。