要显示计数,请使用聚合函数COUNT(*)。让我们首先创建一个表-
create table DemoTable1321 -> ( -> ArrivalDatetime timestamp -> );
使用插入命令在表中插入一些记录-
insert into DemoTable1321 values(now()); insert into DemoTable1321 values('2019-01-10 12:34:00'); insert into DemoTable1321 values('2019-06-12 11:34:00'); insert into DemoTable1321 values('2019-06-12 04:50:00'); insert into DemoTable1321 values('2019-09-18 10:50:45'); insert into DemoTable1321 values('2019-06-12 06:10:20');
使用select语句显示表中的所有记录-
select * from DemoTable1321;
输出结果
+---------------------+ | ArrivalDatetime | +---------------------+ | 2019-09-18 21:49:17 | | 2019-01-10 12:34:00 | | 2019-06-12 11:34:00 | | 2019-06-12 04:50:00 | | 2019-09-18 10:50:45 | | 2019-06-12 06:10:20 | +---------------------+ 6 rows in set (0.00 sec)
以下是计算日期的查询-
select date(ArrivalDatetime) as OnlyDate,count(*) as Total from DemoTable1321 -> group by date(ArrivalDatetime) -> order by date(ArrivalDatetime);
输出结果
+------------+-------+ | OnlyDate | Total | +------------+-------+ | 2019-01-10 | 1 | | 2019-06-12 | 3 | | 2019-09-18 | 2 | +------------+-------+ 3 rows in set (0.00 sec)