feklee feklee -4 years ago 54
MySQL Question

Average number of rows created per day?

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?

Answer Source

This will return an int number:

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download