让我们首先创建一个表-
mysql> create table DemoTable835( CountryCode int, CountryName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable835 values(100,'US'); mysql> insert into DemoTable835 values(101,'UK'); mysql> insert into DemoTable835 values(102,'AUS'); mysql> insert into DemoTable835 values(103,'ENG');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable835;
这将产生以下输出-
+-------------+-------------+ | CountryCode | CountryName | +-------------+-------------+ | 100 | US | | 101 | UK | | 102 | AUS | | 103 | ENG | +-------------+-------------+ 4 rows in set (0.00 sec)
以下是将两个列的值连接到一个列中的查询-
mysql> select concat(CountryCode,'-',CountryName) from DemoTable835;
这将产生以下输出-
+-------------------------------------+ | concat(CountryCode,'-',CountryName) | +-------------------------------------+ | 100-US | | 101-UK | | 102-AUS | | 103-ENG | +-------------------------------------+ 4 rows in set (0.00 sec)