MySQL SELECT (COLNAME) 中的括号是什么意思?
SELECT(COLNAME) 意味着我们正在为该列创建一个别名。让我们看一个示例并创建一个表 -
mysql> create table DemoTable865( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.77 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable865 values('Chris','Brown'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable865 values('Adam','Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable865 values('David','Miller'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable865 values('Carol','Taylor'); Query OK, 1 row affected (0.15 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable865;
这将产生以下输出 -
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Chris | Brown | | Adam | Smith | | David | Miller | | Carol | Taylor | +-----------+----------+ 4 rows in set (0.00 sec)
在这里,我们正在使用 SELECT (COLNAME) MySQL 为列创建别名 -
mysql> select (FirstName) StudentFirstName,(LastName) StudentLastName from DemoTable865;
这将产生以下输出 -
+------------------+-----------------+ | StudentFirstName | StudentLastName | +------------------+-----------------+ | Chris | Brown | | Adam | Smith | | David | Miller | | Carol | Taylor | +------------------+-----------------+ 4 rows in set (0.00 sec)
广告