获取 MySQL 表中指定日期的计数
我们首先创建一个表 −
mysql> create table DemoTable1946 ( ShippingDate date ); Query OK, 0 rows affected (0.00 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2018-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2017-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-04-22'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2019-12-11'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1946 values('2015-12-11'); Query OK, 1 row affected (0.00 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1946;
这会生成以下输出 −
+--------------+ | ShippingDate | +--------------+ | 2019-12-11 | | 2018-12-11 | | 2017-12-11 | | 2019-04-22 | | 2019-12-11 | | 2015-12-11 | +--------------+ 6 rows in set (0.00 sec)
以下是统计特定日期的查询 −
mysql> select count(*) from DemoTable1946 where date(ShippingDate)='2019-12-11';
这会生成以下输出 −
+----------+ | count(*) | +----------+ | 2 | +----------+ 1 row in set (0.00 sec)
广告