在 MySQL 中显示不同的列名
让我们创建一个表 -
mysql> create table DemoTable1996 ( ShippingDate datetime, CustomerName varchar(20) ); Query OK, 0 rows affected (0.84 sec)
使用插入命令在表中插入一些记录 -
mysql> insert into DemoTable1996 values('2019-12-21 10:45:00','Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1996 values('2019-12-21 12:10:00','David'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1996 values('2019-12-20 12:10:00','Bob'); Query OK, 1 row affected (0.14 sec)
使用 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)
广告