表 DB2
ID HOURS HOURSMINUTES
1000 480.5 30:30:00
我想得到 HOURS - HOURSMINUTES
ID HOURS - HOURSMINUTES
1000 450.0
HOURS 是 HOURS 中的浮点值 - 所以 480.5 小时。HOURSMINUTES 是字符串值:30:30:00(30 小时 30 分 00 秒)
怎么减?
这是我的完整表达,因为我从两个表中获取值(我以这种格式获取它们,但我不能减去)。我已经从两种时间戳格式中减去 HOURS - 结果是浮点数。累积时间是字符串值。
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES
from t1
join t2 on t2.id=t1.id
当我尝试在下面插入解决方案时,出现错误。
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2)- cast(substr(t2.cumulativetime, 1, 2) as int) -
(cast(substr(t2.cumulativetime, 4, 2) as int) / 60.0) as diff
from t1
join t2 on t2.id=t1.id
我也试过 Kapil 版本:
select t1.id,
dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) as HOURS,t2.cumulativetime as HOURSMINUTES,
(dec (( timestampdiff(
4,
char(t1.actualfinish - t1.reportdate))/60.00),10,2) - (CAST(substr(t2.cumulativetime , 1, 2) AS float) + CAST(substr(t2.cumulativetime , 4, 2) AS float)/60 + CAST(substr(t2.cumulativetime , 7, 2) AS float)/3600)) as diff
from t1
join t2 on t2.id=t1.id