In Microsoft SQL server, how to count in-between rows based on the values from the same column.
Example
/-----------------------------------------\
| ID ---------- Event -------- UserID ----|
| 1 ----------- START -------- 000001 ----|
| 2 ----------- START -------- 000002 ----|
| 3 ----------- END -------- 000001 ----|
| 4 ----------- PL -------- 000002 ----|
| 5 ----------- END -------- 000002 ----|
\-----------------------------------------/
Consider for UserID
000002, which has 3 rows present and the ID are 2, 4 & 5.
Based on the query from this link I am able to get the START
and END
time, but how to get the count of rows between START
and END
for each USERID
Expected Result
/-------------------------------------------------------\
| UserID ------------------------- Row Count -----------|
| 000001 ------------------------- 2 -----------|
| 000002 ------------------------- 3 -----------|
\-------------------------------------------------------/