sql server - SQL TSQL for Workers per Hour -
i have log fingerprint timestamps follows:
usr timestamp ------------------------- 1 2015-07-01 08:01:00 2 2015-07-01 08:05:00 3 2015-07-01 08:07:00 1 2015-07-01 10:05:00 3 2015-07-01 11:00:00 1 2015-07-01 12:01:00 2 2015-07-01 13:03:00 2 2015-07-01 14:02:00 1 2015-07-01 16:03:00 2 2015-07-01 18:04:00
and wish output of workers per hour (rounding nearest hour) theoretical output should be:
7:00 0 8:00 3 9:00 3 10:00 2 11:00 1 12:00 2 13:00 1 14:00 2 15:00 2 16:00 1 17:00 1 18:00 0 19:00 0
can think on how approach sql or if no other way, through tsql?
edit: timestamps logins , logouts of different users. @ 8am 3 users logged in , same 3 still working @ 9am. 1 of them leaves @ 10am. etc
to start can use datepart hours days following , use group user
select datepart(hour, getdate());
select convert(varchar(5),datepart(hour, timestamp)) + ':00' time, count(usr) users tbl group datepart(hour, timestamp)
Comments
Post a Comment