ID HOURS HOURSMINUTES
1000 480.5 30:30:00
我想HOURS - HOURSMINUTES
ID HOURS - HOURSMINUTES
1000 450.0
小時在小時 - float,因此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
我也試過卡皮爾版本:
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
你可以試試嗎? \t'選擇\t t1.id, \t \t \t DEC((TIMESTAMPDIFF(4,焦炭(t1.actualfinish - t1.reportdate))/ 60.00),10,2),爲小時, \t \t \t t2.cumulativetime如HOURSMINUTES, \t \t \t鑄造(SUBSTR(t2.cumulativetime,1,2)爲INT)作爲hhdif, \t \t \t(鑄造(SUBSTR(t2.cumulativetime,4,2),爲INT)/ 60.0)作爲mmdiff \t from \t t1在t2.id = t1.id處加入t2 請發佈輸出或錯誤消息 – paul 2012-07-12 12:03:26
paul我成功的問題是,我的專欄中的一個值是512:30:30所以substr(1,2)(4,2)它採取無效值(「:」被包含)。那麼如何解決呢?在HOURSMINUTES列中,如果小數點後的小數位數字需要幾小時才能使用,謝謝 – Dejan 2012-07-12 12:10:05