每天创建的平均行数?

时间:2020-12-02 15:49:52

Example table structure:

示例表结构:

+-------------------------+---------------+------+-----+-----------------------+-----------------------------+
| Field                   | Type          | Null | Key | Default               | Extra                       |
+-------------------------+---------------+------+-----+-----------------------+-----------------------------+
| id                      | char(25)      | NO   | PRI | NULL                  |                             |
| created_at              | timestamp     | NO   |     | CURRENT_TIMESTAMP     | on update CURRENT_TIMESTAMP |
+-------------------------+---------------+------+-----+-----------------------+-----------------------------+

How do I find out the average number of rows added per day?

如何计算每天添加的行数?

2 个解决方案

#1


24  

This will return an int number:

这将返回一个int数:

select count(*) / count(distinct date(created_at))
from your_table

To get a decimal number use:

要得到一个十进制数的使用:

select count(*) * 1.0 / count(distinct date(created_at))
from your_table

#2


13  

SELECT AVG(rowsPerDay) AS avgPerDay
FROM ( SELECT 
         COUNT(*) AS rowsPerDay
       FROM tbl
       GROUP BY DATE(created_at)
     ) AS a
;

#1


24  

This will return an int number:

这将返回一个int数:

select count(*) / count(distinct date(created_at))
from your_table

To get a decimal number use:

要得到一个十进制数的使用:

select count(*) * 1.0 / count(distinct date(created_at))
from your_table

#2


13  

SELECT AVG(rowsPerDay) AS avgPerDay
FROM ( SELECT 
         COUNT(*) AS rowsPerDay
       FROM tbl
       GROUP BY DATE(created_at)
     ) AS a
;