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查询会更快执行吗?
答案 0 :(得分:1)
使用子选择:
SELECT AVG(totalCount) FROM (
SELECT DATE( DATE ) DATE, COUNT( number ) totalCOunt
FROM numbers
GROUP BY DATE( DATE )
LIMIT 0 , 30) TBL1