小编典典

MySQL选择条件条件

mysql

我正在尝试将其编译。.我有一个带有firstname和lastname字段的表,并且我有一个字符串,例如“ Bob Jones”或“ Bob Michael
Jones”等。

事实是,例如我姓鲍勃,姓迈克尔·琼斯

所以我想

SELECT neededfield, CONCAT(firstname, ' ', lastname) as firstlast 
  FROM users 
 WHERE firstlast = "Bob Michael Jones"

但是它说未知列“ firstlast” ..有人可以帮助吗?


阅读 571

收藏
2020-05-17

共1个答案

小编典典

您提供的别名用于查询的输出-它们本身在查询中不可用。

您可以重复表达:

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"
2020-05-17