Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL. Average entries per month

Tags:

sql

I have some abstract entry in DB and it's creation date. How can I get average entries created per month?

Edit:

Table has Name field and CreationDate field.

like image 762
sunprophit Avatar asked Nov 25 '11 15:11

sunprophit


People also ask

How do you calculate average monthly balance in SQL?

What the query has to do is to calculate the balance for every day in the month, sum up the amounts and then divide it by the number of days in the current month. If there is no transaction on a given day, the balance stays the same.

How do you find the average of records in SQL?

The avg() function has the following syntax: SELECT AVG( column_name ) FROM table_name; The avg() function can be used with the SELECT query for retrieving data from a table.

What does AVG () do in SQL?

The AVG() function returns the average value of a numeric column.

How do I get the month wise count in SQL?

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


1 Answers

SELECT count(*) AS count, MONTH(date_column) as mnth
FROM table_name
GROUP BY mnth

Should work for you

Edit:

SELECT AVG(a.count) AS avg 
FROM ( SELECT count(*) AS count, MONTH(date_column) as mnth
       FROM table_name
       GROUP BY mnth) AS a
like image 99
Lee Avatar answered Oct 04 '22 17:10

Lee