Fetch the count of a specific date in a MySQL table


Let us first create a table −

mysql> create table DemoTable1946
   (
   ShippingDate date
   );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

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)

Display all records from the table using select statement −

mysql> select * from DemoTable1946;

This will produce the following output −

+--------------+
| 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)

Here is the query to count a specific date −

mysql> select count(*) from  DemoTable1946 where date(ShippingDate)='2019-12-11';

This will produce the following output −

+----------+
| count(*) |
+----------+
|        2 |
+----------+
1 row in set (0.00 sec)

Updated on: 31-Dec-2019

403 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements