需求:
網(wǎng)關(guān)每秒鐘會(huì)向的大數(shù)據(jù)平臺(tái)傳輸數(shù)據(jù),每秒鐘的條數(shù)存在mysql數(shù)據(jù)表中 t_total
(id , update_time , count ).要求統(tǒng)計(jì)每分鐘數(shù)據(jù)量
分析:
數(shù)據(jù)是每秒鐘記錄的傳送條數(shù)邓尤,需要按照分鐘來group by 那么就把時(shí)間轉(zhuǎn)成時(shí)間戳,然后整除60再做統(tǒng)計(jì)
SELECT
t.update_time,t.update_timestamp,SUM(t.count)
FROM
(
SELECT
o.update_time,
floor(
UNIX_TIMESTAMP(o.update_time) / 60
) update_timestamp,
o.count
FROM
`t_total` o
ORDER BY
o.update_time
) AS t group BY t.update_timestamp ORDER BY
t.update_time;