SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 LOGIN & LOGOUT
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vipinjha123
Starting Member

India
45 Posts

Posted - 05/22/2012 :  05:28:30  Show Profile  Reply with Quote
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

India
22460 Posts

Posted - 05/22/2012 :  08:07:35  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000