Fetch how many people are registering on the current date with MySQL

MySQLMySQLi Database

<p>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 &minus;</p><pre class="result notranslate">mysql&gt; select curdate() ; +------------+ | curdate() &nbsp;| +------------+ | 2019-11-30 | +------------+ 1 row in set (0.00 sec)</pre><p>Let us first create a table &minus;</p><pre class="result notranslate">mysql&gt; create table DemoTable1819 &nbsp; &nbsp; &nbsp;( &nbsp; &nbsp; &nbsp;Name varchar(20), &nbsp; &nbsp; &nbsp;RegisteringDate datetime &nbsp; &nbsp; &nbsp;); Query OK, 0 rows affected (0.00 sec)</pre><p>Insert some records in the table using insert command &minus;</p><pre class="result notranslate">mysql&gt; insert into DemoTable1819 values(&#39;Chris&#39;,&#39;2019-11-29 12:30:34&#39;); Query OK, 1 row affected (0.00 sec) mysql&gt; insert into DemoTable1819 values(&#39;David&#39;,&#39;2019-11-30 12:30:34&#39;); Query OK, 1 row affected (0.00 sec) mysql&gt; insert into DemoTable1819 values(&#39;Mike&#39;,&#39;2019-12-30 12:30:34&#39;); Query OK, 1 row affected (0.00 sec) mysql&gt; insert into DemoTable1819 values(&#39;Sam&#39;,&#39;2018-11-30 11:00:00&#39;); Query OK, 1 row affected (0.00 sec) mysql&gt; insert into DemoTable1819 values(&#39;Carol&#39;,&#39;2019-11-30 10:00:00&#39;); Query OK, 1 row affected (0.00 sec)</pre><p>Display all records from the table using select statement &minus;</p><pre class="prettyprint notranslate" style="">mysql&gt; select * from DemoTable1819;</pre><p>This will produce the following output &minus;</p><pre class="result notranslate">+-------+---------------------+ | Name &nbsp;| RegisteringDate &nbsp; &nbsp; | +-------+---------------------+ | Chris | 2019-11-29 12:30:34 | | David | 2019-11-30 12:30:34 | | Mike &nbsp;| 2019-12-30 12:30:34 | | Sam &nbsp; | 2018-11-30 11:00:00 | | Carol | 2019-11-30 10:00:00 | +-------+---------------------+ 5 rows in set (0.00 sec)</pre><p>Here is the query to fetch how many people are registering on the current date &minus;</p><pre class="prettyprint notranslate">mysql&gt; select count(RegisteringDate) as Output from DemoTable1819 WHERE DATE(RegisteringDate) = CURDATE() GROUP BY MONTH(RegisteringDate);</pre><p>This will produce the following output &minus;</p><pre class="result notranslate">+--------+ | Output | +--------+ | &nbsp; &nbsp; &nbsp;2 | +--------+ 1 row in set (0.00 sec)</pre>
raja
Updated on 25-Feb-2020 13:06:28

Advertisements