I am currently developing an application that makes use of an SQL database. In this database I maintain a table called session, which has three fields: a session id (int), a date_created (datetimeoffset), and a date_expired (datetimeoffset) field.
I want to group my sessions in clusters of sessions that the minimum date_created and the maximum date_expired of the sessions not to be more than 6 hours. Also, I don’t want my groups to overlap, i.e. If session s1 belongs to group 1, I do not want it to be also in group 2.
Any ideas?
I suggest you create your 4 data groups like 0-6, 6-12, 12-18 and 18-24, so you can do like this:
FYI: for the sake of simplicity, I did the
caseon the date column only, you will need to use a datediff between your date_created and date_expiredFYI2: change the values on the between as it suits you better and in the end the query will return values to 1, 2, 3 and 4, which you should change to “0 to 6”, “6 to 12” and so one..