SQL。每月平均参赛作品

时间:2011-11-25 15:23:59

标签: sql

我在DB中有一些抽象的条目,它的创建日期。如何获得每月创建的平均条目?

修改

表有名称字段和CreationDate字段。

3 个答案:

答案 0 :(得分:15)

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

应该适合你

编辑:

SELECT AVG(a.count) AS avg 
FROM ( SELECT count(*) AS count, MONTH(date_column) as mnth
       FROM table_name
       GROUP BY mnth) AS a

答案 1 :(得分:3)

试试这个

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

没有子查询

答案 2 :(得分:1)

使用此查询,您将获得值

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