Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vipinjha123
Starting Member
45 Posts |
Posted - 2012-05-22 : 05:28:30
|
Dear All ,I am having a table login(empid,logindate,location)logintime column contains both logindate and logoutdateminimum date of perticular day is logintime nad maxim date of same day is logouttime.i want to know ho many person login and logout on hourly basiswhat i am looking for every hour some person login and same time some person logout so i need a output likesum of all employee who are currently in office on hourly basis.suppose at 8am 20 peson login and at the same time 5 person logout so my count wil be 15 at 8am. means at 8 am 15 people are currently in office.i am looking for result likecountofemplogin countopepeoplelogout inoffice hour 20 5 15 8am Regards,Vipin jha |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-22 : 08:07:35
|
select empid,count(login) as countofemplogin,sum(case when login=logout then 0 else 1 end) as countofemplogout from(select empid,min(loginndate) as login,max(loginndate) as logout from tablegroup by empid) as tgroup by empidMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|