data
id amount created_at
"1" "105" "2018-01-28 15:22:00"
"2" "120" "2018-01-28 15:23:00"
"3" "200" "2018-01-28 15:24:00"
"4" "205" "2018-01-28 15:24:10"
"5" "230" "2018-01-28 15:25:00"
This is my table fields and data, my cronjob running every minute, but for some reason, it might run again at the same minute, therefore I need to filter the data group by the date to minute
What I tried
SELECT COUNT(*), SUM(`amount`), MAX(`amount`), MIN(`amount`)
FROM (
SELECT *
FROM `stats`
GROUP BY DATE_FORMAT(`created_at`, '%Y-%m-%d %H:%i')
) AS tmp
GROUP BY DATE_FORMAT(`created_at`, '%Y-%m-%d %H:%i')
The result is exactly what I need, but I heard subquery is always the last choice because of the efficiency issue, is there another way to do it?
"1" "105" "105" "105"
"1" "120" "120" "120"
"1" "200" "200" "200"
"1" "230" "230" "230"