我想知道我应该采用什么方法来计算每对时间戳之间的时间总和。
示例:
4 '08/02/2018 11:14'
3 '08/02/2018 11:13'
2 '08/02/2018 11:13'
1 '08/02/2018 11:12'
此功能应打开CSV文件/输入
以分钟为单位的时间: 1和2 = 1分钟, 2和3 = 0分钟, 3和4 = 1分钟,然后我需要将差异的所有结果总和为总和,并作为字符串返回。
请从我的CSV数据中查看想法
ROW NO | DATETIMESTAMP | Minutes
----------------------------------------
36. '08/02/2018 11:14' +1 min
35. '08/02/2018 11:13' +0 min
34. '08/02/2018 11:13' +1 min
33. '08/02/2018 11:12' +0 min
32. '08/02/2018 11:12' +4 min
31. '08/02/2018 11:08' +0 min
30. '08/02/2018 11:08' +1 min
29. '08/02/2018 11:07' +0 min
28. '08/02/2018 11:07' +1 min
27. '08/02/2018 11:06' +1 min
26. '08/02/2018 11:05' +2 min
25. '08/02/2018 11:03' +2 min
24. '08/02/2018 11:01' +2 min
23. '08/02/2018 10:59' +2 min
22. '08/02/2018 10:57' +2 min
21. '08/02/2018 10:55' +1 min
20. '08/02/2018 10:54' +3 min
19. '08/02/2018 10:51' +27 min
18. '08/02/2018 10:24' +4 min
17. '08/02/2018 10:20' +2 min
16. '08/02/2018 10:18' +8 min
15. '08/02/2018 10:10' +2 min
14. '08/02/2018 10:08' +2 min
13. '08/02/2018 10:06' +0 min
12. '08/02/2018 10:06' +2 min
11. '08/02/2018 10:04' +2 min
10. '08/02/2018 10:02' +0 min
9. '08/02/2018 10:02' +2 min
8. '08/02/2018 10:00' +1 min
7. '08/02/2018 09:49' +10 min
6. '08/02/2018 09:39' +3 min
5. '08/02/2018 09:36' +1 min
4. '08/02/2018 09:35' +1 min
3. '08/02/2018 09:34' +3 min
2. '08/02/2018 09:31' +1 min
1. '08/02/2018 09:30' -- start of data set
所以函数应该:
在这种情况下应该是94分钟= 01h:34分钟:00
答案 0 :(得分:1)
如果将1与2进行比较,则失败安全请求是无意义的,然后将2与3进行比较,因此我将忽略它..
如果您想在MySQL中执行此操作,可以执行以下操作:
DROP TABLE IF EXISTS my_table;
CREATE TABLE my_table
(id SERIAL PRIMARY KEY
,dt DATETIME NOT NULL
);
INSERT INTO my_table (dt) VALUES
('2018/08/02 11:14:00'),
('2018/08/02 11:13:00'),
('2018/08/02 11:13:00'),
...
('2018/08/02 09:34:00'),
('2018/08/02 09:31:00'),
('2018/08/02 09:30:00');
SELECT SEC_TO_TIME(TIME_TO_SEC(MAX(dt))-TIME_TO_SEC(MIN(dt))) x
FROM my_table;
+----------+
| x |
+----------+
| 01:44:00 |
+----------+