Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Count records for every month in a year

I have a table with total no of 1000 records in it.It has the following structure:

EMP_ID EMP_NAME PHONE_NO   ARR_DATE 1        A        545454 2012/03/12 

I want to calculate no of records for every month in year-2012

Is there any way that should solve my issue in a single shot?

I tried:

select count(*)  from table_emp  where year(ARR_DATE) = '2012' and month(ARR_DATE) = '01' 
like image 318
manoj kumar singh Avatar asked Mar 27 '12 10:03

manoj kumar singh


People also ask

How do I count monthly records in SQL?

Calculate Monthly Sales Report in MySQL If you only want a total count of sales every month, then you can use COUNT function instead. mysql> select year(order_date),month(order_date),sum(sale) from sales WHERE condition group by year(order_date),month(order_date) order by year(order_date),month(order_date);

What is the count of purchases per month in SQL?

You can also find out the total count of sales every month. For that, replace the SUM function with the COUNT function. Query: SELECT YEAR(Order_date) AS Year,MONTH(Order_date) AS Month,COUNT(Sales) AS Count_Of_Sales FROM Products GROUP BY YEAR(Order_date),MONTH(Order_date);

What is count of records?

A count of records contained within a data set submission.


2 Answers

SELECT    COUNT(*)  FROM      table_emp  WHERE     YEAR(ARR_DATE) = '2012'  GROUP BY  MONTH(ARR_DATE) 
like image 65
Dan Avatar answered Sep 23 '22 03:09

Dan


This will give you the count per month for 2012;

SELECT MONTH(ARR_DATE) MONTH, COUNT(*) COUNT FROM table_emp WHERE YEAR(arr_date)=2012 GROUP BY MONTH(ARR_DATE); 

Demo here.

like image 20
Joachim Isaksson Avatar answered Sep 22 '22 03:09

Joachim Isaksson