在MySQL数据库中,我已将数据插入“叶子”表中:
+--------+---------+---------+-------------------------------+-----
|Id_LEAVE|ID_WORKER| BEGIN_DATE | END_DATE |
+--------+---------+------------+--------------------+------------+
| 4 | 26 | 2019-03-19 07:00:00 |2019-03-19 15:00:00 |
+--------+---------+---+----------------------+-------------------+
| 5 | 25 | 2019-03-20 07:00:00 |2019-03-21 15:00:00 |
+--------+---------+---------+----------------------+-------------+
| 6 | 21 | 2019-03-22 07:00:00 |2020-03-22 15:00:00 |
+--------+---------+---------+----------------------+-------------+
然后,我想显示所有带有计算出的休假时间,但没有TIME_FORMAT
和SEC_TO_TIME
的休假时间,因为我知道它有一个值限制。当我执行以下代码时:
select
ID_LEAVE, ID_WORKER, BEGIN_DATE, END_DATE,
concat_ws(' ',
concat((sec DIV 60*60), 'h'),
concat((sec DIV 60) % 60, 'm'),
concat(sec % 60, 's')
) AS 'LEAVE TIME'
from (
select
SUM(
to_seconds(
TIMEDIFF(END_DATE, BEGIN_DATE)
)
) sec,
ID_LEAVE,
ID_WORKER,
BEGIN_DATE,
END_DATE
from
leaves group by ID_LEAVE
) s;
然后我显示所有这些,但是在LEAVE TIME列中仅显示空值:
+--------+---------+---------+------------+-----------------------+-----------+
|Id_LEAVE|ID_WORKER| BEGIN_DATE | END_DATE |LEAVE_TIME |
+--------+---------+------------+--------------------+------------+-----------+
| 4 | 26 | 2019-03-19 07:00:00 |2019-03-19 15:00:00 | |
+--------+---------+---+----------------------+-------------------+-----------+
| 5 | 25 | 2019-03-20 07:00:00 |2019-03-21 15:00:00 | |
+--------+---------+---------+----------------------+-------------+-----------+
| 6 | 21 | 2019-03-22 07:00:00 |2020-03-22 15:00:00 | |
+--------+---------+---------+----------------------+-------------+-----------+
我有一个问题:哪里不显示LEAVE_TIME的值的错误。我应该修复Mysql代码的哪几行?感谢任何帮助。
答案 0 :(得分:0)
尝试一下,也许可以帮忙
SELECT *,FROM_UNIXTIME(
UNIX_TIMESTAMP(
TIMEDIFF(END_DATE,BEGIN_DATE)
),
'%h Hours,%i Minutes,%s Seconds')
as 'LEAVE TIME'
FROM `leaves`