我无法弄清楚如何分析这些数据

时间:2014-01-09 19:28:29

标签: crystal-reports formula

我试图在Crystal中提取报告时遇到问题。以下是我需要提取的数据字段示例。这是一个特定事件的数据。

inci_id     timestamp             transtyp  descript        unitcode
140102994   1/3/2014  10:20:56 AM   D   Dispatched  E16
140102994   1/3/2014  10:20:56 AM   D   Dispatched  E13
140102994   1/3/2014  10:20:56 AM   DXY DispatchXY  E13
140102994   1/3/2014  10:20:56 AM   D   Dispatched  R13
140102994   1/3/2014  10:20:56 AM   DXY DispatchXY  R13
140102994   1/3/2014  10:20:57 AM   D   Dispatched  TK10
140102994   1/3/2014  10:20:57 AM   D   Dispatched  E10
140102994   1/3/2014  10:20:57 AM   DXY DispatchXY  E10
140102994   1/3/2014  10:20:57 AM   DXY DispatchXY  R10
140102994   1/3/2014  10:20:57 AM   D   Dispatched  R10
140102994   1/3/2014  10:20:57 AM   D   Dispatched  BC3
140102994   1/3/2014  10:20:57 AM   DXY DispatchXY  BC3
140102994   1/3/2014  10:20:58 AM   D   Dispatched  FTO3
140102994   1/3/2014  10:20:58 AM   DXY DispatchXY  FTO3
140102994   1/3/2014  10:20:58 AM   D   Dispatched  TAC1
140102994   1/3/2014  10:22:13 AM   AK  {E13} STATION ACKNOWLEDGE   E13
140102994   1/3/2014  10:22:19 AM   AK  {E10} STATION ACKNOWLEDGE   E10
140102994   1/3/2014  10:22:21 AM   E   En-Route    R10
140102994   1/3/2014  10:22:24 AM   AK  {FTO3} STATION ACKNOWLEDG   FTO3
140102994   1/3/2014  10:22:30 AM   AK  {E16} STATION ACKNOWLEDGE   E16
140102994   1/3/2014  10:22:38 AM   E   En-Route    E16
140102994   1/3/2014  10:22:46 AM   E   En-Route    FTO3
140102994   1/3/2014  10:22:58 AM   AK  {BC3} STATION ACKNOWLEDGE   BC3
140102994   1/3/2014  10:23:10 AM   ARM Added Remarks   
140102994   1/3/2014  10:23:12 AM   E   En-Route    E10
140102994   1/3/2014  10:23:14 AM   E   En-Route    E13
140102994   1/3/2014  10:23:18 AM   ARM Added Remarks   
140102994   1/3/2014  10:23:19 AM   ARM Added Remarks   
140102994   1/3/2014  10:23:22 AM   E   En-Route    TK10
140102994   1/3/2014  10:23:24 AM   E   En-Route    R13
140102994   1/3/2014  10:25:11 AM   E   En-Route    BC3
140102994   1/3/2014  10:26:51 AM   ARM Added Remarks   
140102994   1/3/2014  10:27:37 AM   ARM Added Remarks   
140102994   1/3/2014  10:27:39 AM   ARM Added Remarks   
140102994   1/3/2014  10:27:39 AM   IC  {E16} INCIDENT COMMAND  E16
140102994   1/3/2014  10:28:12 AM   A   Arrived E16
140102994   1/3/2014  10:28:41 AM   A   Arrived R13
140102994   1/3/2014  10:28:51 AM   A   Arrived R10
140102994   1/3/2014  10:29:04 AM   A   Arrived E13

我尝试构建的报告需要比较Dispatched(transtype = D)和相同单位Arrives(transtype = A)时特定单位的时间戳,然后从D中减去A给出区别。任何和所有的帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

假设:

inci_id     timestamp               transtyp  descript                    unitcode
140102994   1/3/2014  10:20:56 AM   D         Dispatched                  E16
140102994   1/3/2014  10:22:30 AM   AK        {E16} STATION ACKNOWLEDGE   E16
140102994   1/3/2014  10:22:38 AM   E         En-Route                    E16
140102994   1/3/2014  10:27:39 AM   IC        {E16} INCIDENT COMMAND      E16
140102994   1/3/2014  10:28:12 AM   A         Arrived                     E16

我在此查询中使用了command

SELECT  d.inci_id, d.unitcode, d.timestamp dispatched, a.timestamp arrived
FROM    (
  SELECT inci_id, unitcode, timestamp
  FROM   table
  WHERE  transtyp='D'
)
-- require an 'Arrived' event; switch to LEFT OUTER JOIN if this isn't a requirement
INNER JOIN (
  SELECT inci_id, unitcode, timestamp
  FROM   table
  WHERE  transtyp='A'
) a ON d.inci_id=a.inci_id AND d.unitcode=a.unitcode

每个单位代码都有一行。然后,您可以创建一个公式,为您提供差异:

// {@elapsed}
{command.arrived} - {command.dispatched}