我在一个名为的表中有以下数据TABLE:
编辑:添加了另外几行Characterid: 26052013030101,但被遗漏了。
/---------------------------------------------------- ----------------------\
| 字符ID | 事件类型 | 触发时间 |
|----------------------+--------------------+------ ----------------------|
| 11052016190101 | 开始 | 2017-06-01 13:35:38.000 |
| 11052016190101 | 结束 | 2017-01-06 08:05:18.620 |
| 01012016170101 | 开始 | 2017-06-01 13:33:18.000 |
| 01012016170101 | 球员左 | 2017-06-01 13:35:21.000 |
| 01012016170101 | 结束 | 2017-06-01 13:38:22.000 |
| 26052013030101 | 开始 | 2017-06-01 13:35:39.000 |
| 26052013030101 | 重置 | 2017-06-01 13:35:50.000 |
\-------------------------------------------------- ------------------------------------/
START我已经编写了这个查询来获取基于和END值的时差EVENTTYPE:
SELECT
cp_start.characterid,
MAX(cp_start.triggertime) AS start_time,
cp_end.triggertime AS end_time,
datediff(second, MAX(cp_start.triggertime), cp_end.triggertime)
FROM
TABLE AS cp_start
INNER JOIN
TABLE AS cp_end ON (
cp_start.CharacterID= cp_end.CharacterID
AND
cp_end.triggertime > cp_start.triggertime)
WHERE cp_start.eventtype = 'START'
AND cp_end.eventtype = 'END'
GROUP BY cp_start.characterid, cp_Start.TriggerTime, cp_end.TriggerTime
但是,我们想要的是获得上述条件的时间差 - 即START和END- 如果在 和 之间有任何其他事件START,END那么我们需要跳过那个特定CharacterID的 。
在上面的示例中,请参见CharacterID = 01012016170101,在需要跳过或不考虑EVENTTYPE='Player Left'的行之间有一行行START和END值。EVENTTYPE
编辑:在上面,characterid = 26052013030101,只有开始但没有结束。它有 RESET,这意味着我们在显示结果时不应该考虑这个值。编辑结束
我们如何实现这一目标?
其次,在POWERBI中是否有任何简单的方法可以实现这一点并显示计数和时间差?