sunprophit
sunprophit

Reputation: 1699

SQL. Average entries per month

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.

Upvotes: 14

Views: 43637

Answers (3)

Rashmi Kant Shrivastwa
Rashmi Kant Shrivastwa

Reputation: 1167

hi using this query you will get the value

select avg(entry) as avgentrypermonth from (
select month(DateCreated) as month ,count(1) as entry from table1 group by month(DateCreated)
)q1

Upvotes: 1

Last Rose Studios
Last Rose Studios

Reputation: 2481

try this out

SELECT COUNT(*)/COUNT(DISTINCT MONTH(`datefield`)) FROM tablename

No subqueries

Upvotes: 5

Lee
Lee

Reputation: 10613

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

Upvotes: 19

Related Questions