Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Select as Login counter for sessions in a period of time

$
0
0

Hello all,

I have a SQL database and there is a table with all login sessions (with beginn and end in UNIX timestamp).

I now try to find a select query or something to count the logins in a period of time (week, month, year).

But if a person logs in, from that beginn all of his logins and outs have to be not count from the begin for 24h.

Example:

Mike Start 01.01.2013 - 12:00 End 01.01.2013 - 12:33

Mike Start 01.01.2013 - 15:22 End 01.01.2013 - 16:53

Mike Start 01.01.2013 - 20:01 End 01.01.2013 - 21:49

Mike Start 02.01.2013 - 15:00 End 02.01.2013 - 17:33

Mike Start 02.01.2013 - 18:21 End 02.01.2013 - 20:11

....

Has to be count as 2, because Mike start on 01.01.2013 - 12:00 so from there for 24h (mean until 02.01.2013) is only one. Second and third login are in this period and so not counted. Then the 24h from first login are over. He logs in again, gets count, but next session is in this period of 24h and not count, again.

I know that seems to bee not very easy. I think for this query are only Loginname, Starttime and Endtime necessary.

I tryed with something like that:

SELECTCASEWHENLoginname =LoginnameandStartTimebetweenStartTimeand StartTime+ 86400 andEndtimebetweenStartTimeand StartTime+ 86400

            THEN ....

      END

FROMTable


You can also use an Update funktion or what ever you think is necessary.

I hope you can help me with that.

kind regards

Mario


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>