我有一个看起来像这样的表'victory_picker_picktask_scanactivity'
PickerID|ObjectScanned| StartTime | EndTime |
------------------------------------------------------------------
2 | Bin |2020-02-17 03:46:58 | 2020-02-17 03:47:13
2 | Bin |2020-02-17 13:34:02 | 2020-02-17 13:34:27
我想找到每天的平均秒数
我正在使用此查询来提取一天,但是我每天都希望将其硬编码为一天
SELECT AVG(TIMESTAMPDIFF(SECOND, `StartTime`, `EndTime`))
as time_in_seconds
FROM `victory_picker_picktask_scanactivity`
WHERE `victory_picker_picktask_scanactivity`.`EndTime` IS NOT NULL
AND `PickerID` = 2
AND `EndTime` < '2020-02-18 00:00:01'
AND `ObjectScanned` = 'Bin'
答案 0 :(得分:0)
假设开始时间和结束时间在同一天:
SELECT DATE(StartTime), AVG(TIMESTAMPDIFF(SECOND, `StartTime`, `EndTime`))
as time_in_seconds
FROM `victory_picker_picktask_scanactivity`
WHERE `victory_picker_picktask_scanactivity`.`EndTime` IS NOT NULL
`PickerID` = 2 AND
`ObjectScanned` = 'Bin'
GROUP BY DATE(StartTime);
答案 1 :(得分:0)
您还可以检查*
和START_DATE
的比较
END_DATE