我试图从日期时间列中使用10分钟的间隔来获取平均值。这么胖我得到这个SQL来获取间隔
的数据 select 1 AS `location_id`,
`raw_datas`.`parsing_at` AS `date`,
count(`raw_datas`.`station_mac`) AS `quantity`
FORM `raw_datas`
WHERE (timediff(`raw_datas`.`parsing_at`,`raw_datas`.`last_time_seen`) <= 20)
GROUP BY UNIX_TIMESTAMP(`raw_datas`.`parsing_at`) DIV 600
order by `raw_datas`.`parsing_at`;
但结果显示已添加
+-------------+---------------------+----------+
| location_id | date | quantity |
+-------------+---------------------+----------+
| 1 | 2016-04-11 05:10:22 | 137 |
| 1 | 2016-04-11 05:20:02 | 121 |
| 1 | 2016-04-11 05:30:02 | 24 |
| 1 | 2016-04-11 06:06:11 | 20 |
| 1 | 2016-04-11 06:10:02 | 36 |
| 1 | 2016-04-11 06:20:02 | 37 |
| 1 | 2016-04-11 06:30:02 | 29 |
| 1 | 2016-04-11 08:46:10 | 7 |
| 1 | 2016-04-11 08:50:02 | 21 |
| 1 | 2016-04-11 09:00:22 | 16 |
| 1 | 2016-04-11 09:10:22 | 16 |
| 1 | 2016-04-11 09:20:02 | 15 |
| 1 | 2016-04-11 09:30:02 | 8 |
| 1 | 2016-04-11 09:41:01 | 1 |
| 1 | 2016-04-11 15:01:02 | 69 |
| 1 | 2016-04-11 15:10:02 | 106 |
| 1 | 2016-04-11 15:20:02 | 69 |
| 1 | 2016-04-11 23:18:02 | 20 |
| 1 | 2016-04-11 23:20:02 | 124 |
| 1 | 2016-04-11 23:30:02 | 105 |
| 1 | 2016-04-11 23:40:02 | 80 |
| 1 | 2016-04-12 22:00:35 | 224 |
| 1 | 2016-04-12 22:10:02 | 191 |
| 1 | 2016-04-12 22:20:02 | 193 |
| 1 | 2016-04-12 22:30:02 | 66 |
+-------------+---------------------+----------+
如何使数量列显示日期列上时间间隔的平均值?
答案 0 :(得分:2)
您可以使用AVG()函数代替count()来获得平均值