- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fetch how many people are registering on the current date with MySQL
For this, you can use COUNT() along with GROUP BY MONTH(). To match with the current date, use CURRENT_DATE(). The current date is as follows −
mysql> select curdate() ; +------------+ | curdate() | +------------+ | 2019-11-30 | +------------+ 1 row in set (0.00 sec)
Let us first create a table −
mysql> create table DemoTable1819 ( Name varchar(20), RegisteringDate datetime ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1819 values('Chris','2019-11-29 12:30:34'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1819 values('David','2019-11-30 12:30:34'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1819 values('Mike','2019-12-30 12:30:34'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1819 values('Sam','2018-11-30 11:00:00'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1819 values('Carol','2019-11-30 10:00:00'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1819;
This will produce the following output −
+-------+---------------------+ | Name | RegisteringDate | +-------+---------------------+ | Chris | 2019-11-29 12:30:34 | | David | 2019-11-30 12:30:34 | | Mike | 2019-12-30 12:30:34 | | Sam | 2018-11-30 11:00:00 | | Carol | 2019-11-30 10:00:00 | +-------+---------------------+ 5 rows in set (0.00 sec)
Here is the query to fetch how many people are registering on the current date −
mysql> select count(RegisteringDate) as Output from DemoTable1819 WHERE DATE(RegisteringDate) = CURDATE() GROUP BY MONTH(RegisteringDate);
This will produce the following output −
+--------+ | Output | +--------+ | 2 | +--------+ 1 row in set (0.00 sec)
Advertisements