MySQL select with CONCAT condition(带有 CONCAT 条件的 MySQL 选择)
问题描述
我正在尝试在我的脑海中编译这个.. 我有一个包含名字和姓氏字段的表我有一个字符串,比如Bob Jones"或Bob Michael Jones"等等.
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.
问题是,例如,我有Bob 的名字,和迈克尔·琼斯的姓
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"
这篇关于带有 CONCAT 条件的 MySQL 选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 CONCAT 条件的 MySQL 选择
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
