From: | "Satish Burnwal (sburnwal)" <sburnwal(at)cisco(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Need Help in query |
Date: | 2010-12-23 09:37:49 |
Message-ID: | 3A8C969225424C4D8E6BEE65ED8552DA03543C1D@XMB-BGL-41C.cisco.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I need a help in writing a query. I have data as follows:
mydb=# select * from usrlog ;
logid | userid | loginhr | logouthr
-------+----------+---------+----------
0 | sburnwal | 0 | 1
1 | rickyrs | 1 | 5
2 | satishbn | 1 | 6
3 | taohujin | 2 | 4
4 | jospehm | 4 | 5
Table captures the login and logout time (taking hour here to simplify)
of users and my aim to find the number of logged-in users (online users)
at every hr (1st hr i.e. 0-1, 2nd hrs i.e. 1-2, 3rd hr i.e. 2-3 and ...
so on). As the data indicates, use is not logging out in same hr as hr
of login. A user can be logged-in for more than one hr. For example,
here user rickyrs is logged-in for 1st, 2nd, 3rd, 4th and 5th hr. My
query needs to find out in the last 24 hrs, how many users were
logged-in at each hr. I want the result this way:
Nth-hr user
---------------------------
1 sburnwal
2 rickyrs
2 satishbn
3 rickyrs
3 satishbn
3 taohujin
4 rickyrs
4 satishbn
4 taohujin
4 josephm
Appreciate your response in advance. For me, even the count of users on
hourly basis is fine.
Thanks
-Satish
From | Date | Subject | |
---|---|---|---|
Next Message | Nicklas Avén | 2010-12-23 10:01:24 | Re: Need Help in query |
Previous Message | Atul Kumar | 2010-12-23 08:52:59 | FW: Issue while using PostgreSql 8.4. |