如何将以下Oracle转换转换为Teradata:
select
round((current_timestamp - ah.adate) - (ah.ahdate-ah.adate),1)
,round(ah.ahdate-ah.addate,1)
from actions ah
答案 0 :(得分:0)
我认为以下比较之一应该适用于Teradata:
SELECT Current_Timestamp - CAST(ah.addate AS TimeStamp(6)) DAY (4) TO SECOND(4) AS TimeInterval
, Current_Date - CAST(ah.addate AS DATE) DAY(4) AS DayInterval /* May Not be necessary as two dates can be subtracted/added without INTERVAL */
, Current_Date - ah.addate AS DayDifference /* If AdDate is a DATE in Teradata */
FROM actions ah
编辑:将时间戳之间的差异细分为秒,然后使用数学计算两个时间戳之间的天数作为FLOAT。
SELECT (((EXTRACT (DAY FROM (Current_Timestamp - Timestamp '2015-04-01 21:13:40' DAY TO SECOND)) * 86400)
+ (EXTRACT (HOUR FROM (Current_Timestamp - Timestamp '2015-04-01 21:13:40' DAY TO SECOND)) * 3600)
+ (EXTRACT (MINUTE FROM (Current_Timestamp - Timestamp '2015-04-01 21:13:40' DAY TO SECOND)) * 60)
+ (EXTRACT (SECOND FROM (Current_Timestamp - Timestamp '2015-04-01 21:13:40' DAY TO SECOND))) AS FLOAT)) / 86400.00
答案 1 :(得分:0)
这是罪恶的丑陋,但它会从两个间隔的减法中得到一个小数位的天数。
SELECT
ROUND(
STRTOK(CAST((TIMESTAMP '2017-04-17 07:08:34.000' - TIMESTAMP '2015-04-09 16:30:14.000' DAY(4) TO HOUR) AS VARCHAR(10)),' ',1) +
(STRTOK(CAST((TIMESTAMP '2017-04-17 07:08:34.000' - TIMESTAMP '2015-04-09 16:30:14.000' DAY(4) TO HOUR) AS VARCHAR(10)),' ',2)/24)
,1)
这里棘手的部分是当你减去两个TIMESTAMPs
时,你最终得到的是INTERVAL
数据类型。我们将该区间数据类型转换为HOUR
,然后将结果转换为VARCHAR
,在此示例中看起来像738 15
。那是738天和15个小时。
使用STRTOK()
,我们可以选出天数(第一个代币),然后加上小时数(第二个代币)除以24。
然后舍入结果。
也许有一种较少参与的方式,但我还没有发现它。
答案 2 :(得分:0)
使用此解决方案: ,修剪(abs((CAST(ah.ahdate AS DATE) - CAST(ah.adate AS DATE)))) ,(演员(修剪(绝对((EXTRACT(HOUR FROM ah.ahdate)) - abs(EXTRACT(HOUR FROM ah.adate)))))作为varchar(10)))/ 24