平均计数组

时间:2014-10-22 18:46:45

标签: mysql sql

SELECT DATE( DATE ) DATE, COUNT( number ) totalCOunt
FROM numbers
GROUP BY DATE( DATE ) 
LIMIT 0 , 30

   DATE    totalCOunt
2013-01-01 13
2013-01-02 12
2013-01-03 22
2013-01-04 14
2013-01-05 14
2013-01-06 16
2013-01-07 13
2013-01-08 22
etc

如何获得此数据的平均值?我做了很多次尝试失败了,我可以在sql或foreach php函数中执行它,但是看起来sql查询会更快执行吗?

1 个答案:

答案 0 :(得分:1)

使用子选择:

SELECT AVG(totalCount) FROM (
    SELECT DATE( DATE ) DATE, COUNT( number ) totalCOunt
    FROM numbers
    GROUP BY DATE( DATE ) 
    LIMIT 0 , 30) TBL1