要创建制表符分隔的select语句,可以使用CONCAT()
MySQL中的function。以下是语法:
select concat(yourColumnName1,"\t",yourColumnName2) AS anyAliasName from yourTableName;
让我们首先创建一个表:
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) );
以下是使用insert命令在表中插入记录的查询:
mysql> insert into DemoTable(FirstName,LastName) values('John','Smith'); mysql> insert into DemoTable(FirstName,LastName) values('Carol','Taylor'); mysql> insert into DemoTable(FirstName,LastName) values('John','Doe'); mysql> insert into DemoTable(FirstName,LastName) values('David','Miller');
以下是使用select命令显示表中记录的查询:
mysql> select *from DemoTable;
这将产生以下输出
+----+-----------+----------+ | Id | FirstName | LastName | +----+-----------+----------+ | 1 | John | Smith | | 2 | Carol | Taylor | | 3 | John | Doe | | 4 | David | Miller | +----+-----------+----------+ 4 rows in set (0.00 sec)
以下是创建制表符分隔的select语句的查询:
mysql> select concat(FirstName,"\t",LastName) AS Tab_Delimited_Demo from DemoTable;
这将产生以下输出:
+--------------------+ | Tab_Delimited_Demo | +--------------------+ | John Smith | | Carol Taylor | | John Doe | | David Miller | +--------------------+ 4 rows in set (0.00 sec)