I am working with data which has a session id value which gets recycled over time (asp session ids from IIS to be exact).
I am trying to give them a sequence so that each instance of an ASP_SESSION_ID don't get grouped together.
For example, the data would look like this. Same session id, used in Aug 2016, then again in March 2017.
DTTM SESSION_ID
2016-08-29 14:24:28.450 297692378
2017-04-13 23:54:53.760 297692378
2017-04-13 23:59:53.477 297692378
2017-04-14 00:04:52.897 297692378
2017-04-14 00:04:53.790 297692378
At first I thought to just group on the date (at the DAY level), but for the example above, notice how the 2nd instance of the session id spans across midnight. That would cause a 3rd group, when really it's the same session.
So if I could rank them properly, it would be:
DTTM SESSION_ID RANK
2016-08-29 14:24:28.450 297692378 1
2017-04-13 23:54:53.760 297692378 2
2017-04-13 23:59:53.477 297692378 2
2017-04-14 00:04:52.897 297692378 2
2017-04-14 00:04:53.790 297692378 2
Here, ASP_SESSION_ID should be considered a new instance of a session when > 20 minutes passed since the last request.
So, how can I group by or rank the same ASP_SESSION_ID differently as they get re-used over time? e.g. if the next request by that ASP_SESSION_ID is > 20 minutes from the last, group it/rank it differently?
I am just not sure how to attack the problem.
Here are some statements to generate the data above:
CREATE TABLE #TEST
(
DTTM DATETIME,
SESSION_ID INT
)
INSERT INTO #TEST (DTTM, SESSION_ID)
select '2016-08-29 14:24:28.450', 297692378 union
select '2017-04-13 23:54:53.760', 297692378 union
select '2017-04-13 23:59:53.477', 297692378 union
select '2017-04-14 00:04:52.897', 297692378 union
select '2017-04-14 00:04:53.790', 297692378