Group by 2 mysql pieces
Mysql table:
I want to take the amount of acceleCount at intervals of 2 minutes.
Query:
select time div 120000 as TwoMinutes,
sum(acceleCount) as Sum
from acceleTable
group by time div 120000
Result:
Here, the timestamp of column twoMinutes is less. I want it to have a time stamp that is within two minutes.
Any thoughts on how to modify the SQL query?
+3
Asiri Liyana Arachchi
source
to share
2 answers
Bring the timestamps to a common denominator by division, rounding and multiplication:
SELECT
(ROUND(time / 120) * 120),
sum(acceleCount)
FROM acceleTable
GROUP BY (ROUND(time / 120) * 120)
+1
DanFromGermany
source
to share
A small optimized way to do it
SELECT (ROUND(time / 120000) * 120000) AS timekey, sum(acceleCount)
FROM acceleTable
GROUP BY timekey
+1
Abhishek gupta
source
to share