Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to do a count on logged in users

Status
Not open for further replies.

kray4660

MIS
Apr 7, 2008
1,054
US
I am trying to build a query where I can get a count of logged in users. There is a field called eventtype. If it is set to one, then the user is logged in. If it is set to seven, then they are logged out. There are a number of other eventtypes that I can ignore. There is a datetime stamp for each eventtype (see sample data below). I might be able to do this in MS-SQL, but the database is Informix which I am not as well versed in. Any assistance would be appreciated.

Sample Data
UserID DateTime Eventtype
11604 6/27/2016 3.05.53 PM 1 login
11604 6/27/2016 3.05.53 PM 2
11604 6/27/2016 3.06.21 PM 3
11604 6/27/2016 3.07.51 PM 4
11604 6/27/2016 3.08.01 PM 5
11604 6/27/2016 3.11.59 PM 6
11604 6/27/2016 3.16.45 PM 3
11604 6/27/2016 3.20.53 PM 7 logout
11604 6/27/2016 3.25.53 PM 1 login
...etc.
 
I found a solution. It is neither elegant or fast.

select
sum(logged_in) as loggedIn,
sum(not_ready) as notReady,
sum(ready) as Ready,
sum(reserved) as Reserved,
sum(talking) as Talking,
sum(work) as Work

from (select

agentid,
case when eventtype = 2 then count(distinct agentid) end as not_ready,
case when eventtype = 3 then count(distinct agentid) end as ready,
case when eventtype = 4 then count(distinct agentid) end as reserved,
case when eventtype = 5 then count(distinct agentid) end as talking,
case when eventtype = 6 then count(distinct agentid) end as work,
case when eventtype <> 7 then count(distinct agentid) end as logged_in

from agentstatedetail asd
where eventdatetime> today
and eventdatetime = (select max(eventdatetime) from agentstatedetail where asd.agentid = agentstatedetail.agentid)
group by agentid, eventtype
order by agentid, max(eventdatetime) desc)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top