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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 LOGIN & LOGOUT

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 logoutdate
minimum 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 basis
what i am looking for every hour some person login and same time some person logout so i need a output like
sum 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 like
countofemplogin 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 table
group by empid
) as t
group by empid



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -