SQL。每月平均条目数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8271130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:24:33 来源:igfitidea点击:
SQL. Average entries per month
提问by sunprophit
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.
表具有名称字段和创建日期字段。
回答by Lee
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
回答by Last Rose Studios
try this out
试试这个
SELECT COUNT(*)/COUNT(DISTINCT MONTH(`datefield`)) FROM tablename
No subqueries
没有子查询
回答by Rashmi Kant Shrivastwa
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