我正在尝试计算SAS EG中两个时间列之间的差异。我正在写一个SQL查询来做到这一点。但我得到的答案不正确。这是我的疑问:
select
Time_DP, Time_AR, (Time_DP-time_AR) as timediff from table1
-------
这就是我得到的
Time_DP Time_AR timediff
23:00:00 20:31:00 22900
00:53:00 23:59:00 -230600
这些只是我得到的两行的例子。我猜他的timdiff值只有几秒钟。如果是这样,第一行的149*60
秒应为8940
,即hh:mm format
。
我还需要02:29
中的这个列,即--DATEDIFF(hour, Time_DP,time_AR ) AS timediff
(Error: Hour is not a column of an inserted table. SQL code = -206, SQL state=42703)
--TIMEDIFF(CAST( AS TIME), CAST(time_AR AS TIME)) AS TIMIFF
(Error: No function by the name timediff having compatible arguments was found in the current path. sql code=-440, sql state=42284)
--DATEADD(SECOND, - DATEDIFF(SECOND, time_AR, Time_DP),) as timediff,
(ERROR: Second is not a column of an inserted table, updated table or any table identified in a from clause.SQL code = -206, SQL state=42703)
--Convert(time(0),(Convert(datetime,Time_DP) - Convert(datetime,Time_AR)),8) as timediff
( ERROR: Datetime is not a column of an inserted table, updated table or any table identified in a from clause.SQL code = -206, SQL state=42703)
--DATEDIFF(HOUR,Time_AR,Time_DP) AS timediff
(ERROR: Hour is not a column of an inserted table, updated table or any table identified in a from clause.SQL code = -206, SQL state=42703)
我尝试使用下面提到的功能,但没有一个能够工作:
{{1}}
由于
答案 0 :(得分:3)
在DB2中,减去两个TIME
值的结果是持续时间,DECIMAL
形式为HHMMSS
。因此,从'23:00:00'减去'20:31:00'给出22900,即2小时29分00秒。从较早时间'00:53:00'减去稍后时间'23:59:00'显然给出负值-230600。