Reputation: 1699
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
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
Reputation: 2481
try this out
SELECT COUNT(*)/COUNT(DISTINCT MONTH(`datefield`)) FROM tablename
No subqueries
Upvotes: 5
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