是的,我们可以使用关键字作为列的别名。以下是语法-select yourColumnName AS `yourKeywordAsAliasName` from yourTableName;
在上方,yourKeywordAsAliasName是MySQL关键字。
让我们首先创建一个表-mysql> create table DemoTable (UserId int);
示例
使用插入命令在表中插入一些记录-mysql> insert into DemoTable values(10);
mysql> insert into DemoTable values(11);
mysql> insert into DemoTable values(12);
mysql> insert into DemoTable values(13);
使用select语句显示表中的所有记录-mysql> select *from DemoTable;
输出结果+--------+
| UserId |
+--------+
| 10 |
| 11 |
| 12 |
| 13 |
+--------+
4 rows in set (0.00 sec)
这是使用MySQL关键字作为列别名的查询。我们已经使用关键字“ PRIMARY KEY”作为列的别名-mysql> select UserId AS `PRIMARY KEY` from DemoTable;
输出结果+-------------+
| PRIMARY KEY |
+-------------+
| 10 |
| 11 |
| 12 |
| 13 |
+-------------+
4 rows in set (0.00 sec)