MySQL计算在线时长(超过2分钟未上传不在计算范围)
生活随笔
收集整理的這篇文章主要介紹了
MySQL计算在线时长(超过2分钟未上传不在计算范围)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
根據上傳時間進行統計,每隔一分鐘上傳一次數據,超過2分鐘也就是120秒沒有數據上傳的話就不納入計算范圍,統計SQL如下:
select t.driverId,t.sumTime,t.countDate,t.orgId,t.name,t.telephone,t.vehicleNo,t.vehicleModel from ( select temp.driver_id driverId, CAST(sum(temp.sum_time) as signed) as sumTime, max(temp.time) countDate, max(id),max(org_id) orgId, max(name) name, max(telephone) telephone, max(vehicle_No) vehicleNo, max(vehicle_model) vehicleModel from( select m.*, @end:=time as endtime, case when m.driver_id=@driver_id then (@sum:=unix_timestamp(@end)-unix_timestamp(@begin)) else 0 end as sum_time, @driver_id:=m.driver_id as temp_driver, @begin:=time as begin_time from (select * from driver_onlinetime_count where time BETWEEN DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day),'%Y-%m-%d 00:00:00') and DATE_FORMAT(DATE_SUB(now(),INTERVAL 1 day),'%Y-%m-%d 23:59:59') order by driver_id,time)m, (select @driver_id:=0,@begin:=0,@end:=0,@sum:=0)n )temp where temp.sum_time <= 120 group by driver_id ) t總結
以上是生活随笔為你收集整理的MySQL计算在线时长(超过2分钟未上传不在计算范围)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL日期及时间加减函数
- 下一篇: TX-LCN分布式事务框架开发文档