使用 MySQL SELECT 在列值末尾添加一个字符?
mysqlmysqli database更新于 2025/10/30 16:12:17
为此,您需要使用 CONCAT() 执行连接。
让我们首先创建一个表 −
mysql> create table DemoTable766 (Name varchar(100)); Query OK, 0 rows affected (0.65 sec)
使用插入命令在表中插入一些记录 −
mysql> insert into DemoTable766 values('John');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable766 values('Sam');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable766 values('Carol');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable766 values('David');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable766 values('Bob');
Query OK, 1 row affected (0.12 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable766;
这将产生以下输出 -
+-------+ | Name | +-------+ | John | | Sam | | Carol | | David | | Bob | +-------+ 5 rows in set (0.00 sec)
以下是在列值末尾添加字符的查询 −
mysql> select concat(Name,' S') from DemoTable766;
这将产生以下输出 -
+-------------------+ | concat(Name,' S') | +-------------------+ | John S | | Sam S | | Carol S | | David S | | Bob S | +-------------------+ 5 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

