MySQL选择CONCAT条件 [英] MySQL select with CONCAT condition
本文介绍了MySQL选择CONCAT条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将其编译..我有一个带有firstname和lastname字段的表 而且我有一个字符串,例如鲍勃·琼斯"或鲍勃·迈克尔·琼斯"以及其他几个字符串.
I'm trying to compile this in my mind.. i have a table with firstname and lastname fields and i have a string like "Bob Jones" or "Bob Michael Jones" and several others.
问题是,例如 鲍勃的名字,以及 迈克尔·琼斯的姓氏
the thing is, i have for example Bob in firstname, and Michael Jones in lastname
所以我正在尝试
SELECT neededfield, CONCAT(firstname, ' ', lastname) as firstlast
FROM users
WHERE firstlast = "Bob Michael Jones"
但是它说未知列"firstlast" ..有人可以帮忙吗?
but it says unknown column "firstlast".. can anyone help please ?
推荐答案
您提供的别名用于查询的输出-在查询本身中不可用.
The aliases you give are for the output of the query - they are not available within the query itself.
您可以重复表达:
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"
这篇关于MySQL选择CONCAT条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文