在MySQL中显示不同的列名称
让我们创建一个表-
mysql> create table DemoTable1996 ( ShippingDate datetime, CustomerName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1996 values('2019-12-21 10:45:00','Chris'); mysql> insert into DemoTable1996 values('2019-12-21 12:10:00','David'); mysql> insert into DemoTable1996 values('2019-12-20 12:10:00','Bob');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1996;
这将产生以下输出-
+---------------------+--------------+ | ShippingDate | CustomerName | +---------------------+--------------+ | 2019-12-21 10:45:00 | Chris | | 2019-12-21 12:10:00 | David | | 2019-12-20 12:10:00 | Bob | +---------------------+--------------+ 3 rows in set (0.00 sec)
这是显示不同列名称的查询-
mysql> select * from DemoTable1996 group by date(ShippingDate);
这将产生以下输出-
+---------------------+--------------+ | ShippingDate | CustomerName | +---------------------+--------------+ | 2019-12-21 10:45:00 | Chris | | 2019-12-20 12:10:00 | Bob | +---------------------+--------------+ 2 rows in set (0.07 sec)