计算疾病时间-如何显示正确的时间而不是MySQL的TIME值限制838:59:59

时间:2019-05-20 10:54:37

标签: mysql hour seconds time-format minute

在这种情况下,我有一个有1年请假天(约360天)的工人:

+--------+---------+---------+-------------+---------+-----------+
|ID_LEAVE|ID_WORKER| BEGIN_DATE          | END_DATE              |
+--------+---------+---------+---------+------------+------------+
| 4      |   26    |2019-03-19 07:00:00  |2020-03-19 15:00:00    |  
+--------+---------+---------+----------------------+------------+

当我要在Mysql命令下运行时,该命令将计算休假时间(无周末和节假日):

SELECT leaves.ID_LEAVE, 
leaves.ID_WORKER, 
workers.IMIE, 
workers.NAZWISKO, 
leaves.BEGIN_DATE, 
leaves.END_DATE, 
TIME_FORMAT(SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(TIME(leaves.END_DATE), TIME(leaves.BEGIN_DATE))))), '%H:%i:%s') AS 'LEAVE TIME' 
FROM (SELECT ADDDATE('1970-01-01', t4 * 10000 + t3 * 1000 + t2 * 100 + t1 * 10 + t0) AS date_value 
FROM (SELECT 0 t0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t0, 
(SELECT 0 t1 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1, 
(SELECT 0 t2 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2, 
(SELECT 0 t3 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3, 
(SELECT 0 t4 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t4) calendar 
INNER JOIN project1.leaves ON calendar.date_value BETWEEN DATE(leaves.BEGIN_DATE) AND DATE(leaves.END_DATE) 
INNER JOIN project1.workers ON leaves.ID_WORKER = workers.ID_WORKER 
WHERE NOT WEEKDAY(date_value) IN (5, 6) AND NOT DATE(date_value) IN (SELECT HOLIDAY_DATE FROM project1.holidays) 
GROUP BY ID_LEAVE;

然后显示如下内容:

+--------+---------+---------+-------------+---------+----------+----------+
|ID_LEAVE|ID_WORKER| BEGIN_DATE          | END_DATE             |LEAVE TIME|
+--------+---------+---------+---------+------------+-----------+----------+
| 4      |   26    |2019-03-19 07:00:00  |2020-03-19 15:00:00   |838:59:59 |
+--------+---------+---------+----------------------+-----------+----------+

时间838:59:59大约是... 35天。

我有麻烦。是否可以精确计算休假时间(格式为HH:mm:ss的1年)?预先感谢您的答复。

0 个答案:

没有答案