我试图找到一种方法来显示事件类型在发生第二个事件类型之前连续发生了多少次。当我需要显示事件类型连续发生6次时
为简化起见,我有一个“通话”表,其中包含
CallID
UserID
Outcome
DateOfCall
Run Code Online (Sandbox Code Playgroud)
从那里,我有许多UserIDs的结果一样Yes或No在不同的时间
我需要找出连续六次没有发生的时间
我目前正在使用Partition,并且已经计算出Outcomes 的数量UserID,但是当Outcome第二次更改时,我正在努力重置行号UserID
select CallID,
UserID,
Outcome,
DateOfCall
rnk = ROW_NUMBER() OVER (PARTITION BY UserID , outcome ORDER BY DateOfCall ASC)
from Calls
order by UserID, DateOfCall
Run Code Online (Sandbox Code Playgroud)
给我以下的UserID
- 19/01/2017 12:00 - Yes - 1
- 19/01/2017 12:01 - Yes - 2
- 19/01/2017 12:02 - Yes - 3
- 19/01/2017 12:03 - No - 1
- 19/01/2017 12:04 - …Run Code Online (Sandbox Code Playgroud)