第一个问题是,如果我在pgAdmin3中运行代码,那么我有这个输出:
但是部署后我得到了这个:
我也可以用这样的文字替换负片时间:
CASE WHEN TRUNC(EXTRACT(EPOCH FROM ((CASE WHEN wo.RESPONDEDTIME= 0
AND wo.RESOLVEDTIME= 0
THEN DATE_TRUNC('second', CURRENT_TIMESTAMP)
ELSE CASE WHEN wo.RESPONDEDTIME= 0
THEN TO_TIMESTAMP(wo.RESOLVEDTIME / 1000)
ELSE TO_TIMESTAMP(wo.RESPONDEDTIME / 1000)
END
END) - (TO_TIMESTAMP(wo.CREATEDTIME / 1000)
+ (((sla.fr_duebydays * 1440)
+ (sla.fr_duebyhours * 60)
+ sla.fr_duebyminutes) * interval '1 minute'))))/60) <0
THEN **'overdue'**
答案 0 :(得分:1)
我已经弄明白了我的两个问题。第一个(带有时间戳格式问题的那个)与我在另一个应用程序(JasperSoft)中解释PostgreSQL查询的事实有关。
解决方法是to_char整个表达式。像这样:
TO_CHAR
(
AGE( CASE WHEN wo.RESPONDEDTIME= 0 AND wo.RESOLVEDTIME= 0
THEN DATE_TRUNC('second', CURRENT_TIMESTAMP)
ELSE CASE WHEN wo.RESPONDEDTIME= 0
THEN TO_TIMESTAMP(wo.RESOLVEDTIME / 1000)
ELSE TO_TIMESTAMP(wo.RESPONDEDTIME / 1000)
END END ,
TO_TIMESTAMP(wo.CREATEDTIME / 1000) + (((sla.fr_duebydays * 1440) + (sla.fr_duebyhours * 60) + sla.fr_duebyminutes) * interval '1 minute')
), 'DD HH24:MI')
我遇到的另一个问题是我从查询中得到的一些负时间戳值。解决方案是,一旦表达式为to_char,我将整个事情包含在一个&#34; case&#34;表达。
像这样:
CASE WHEN wo.RESPONDEDTIME <= 0 -- this case gets read of the negative values in the table
THEN
TO_CHAR
(
AGE( CASE WHEN wo.RESPONDEDTIME= 0 AND wo.RESOLVEDTIME= 0
THEN DATE_TRUNC('second', CURRENT_TIMESTAMP)
ELSE CASE WHEN wo.RESPONDEDTIME= 0
THEN TO_TIMESTAMP(wo.RESOLVEDTIME / 1000)
ELSE TO_TIMESTAMP(wo.RESPONDEDTIME / 1000)
END END ,
TO_TIMESTAMP(wo.CREATEDTIME / 1000) + (((sla.fr_duebydays * 1440) + (sla.fr_duebyhours * 60) + sla.fr_duebyminutes) * interval '1 minute')
), 'DD HH24:MI')
ELSE 'on time' END
AS "Response SLA Violation"