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!

Help needed on SQL request (JOIN + COUNT?)

Status
Not open for further replies.

PanzerKunst

Programmer
May 31, 2005
3
0
0
FR
I have a table HABILIT, whose columns are the following: LOGIN_DATE (date), LOGIN (varchar2), ROLE (varchar2).
Each time a user logs into the web application, an INSERT query is done, inserting the LOGIN and ROLE (application role) of that user at SYSDATE.
Only 2 roles exist : A or B.

Now, what I need is another query, to retreive some stats about these logins.

I need a query which for each day, displays the number of logins of users of role A, and of those of role B, ordered by descending date.

The resultSet I'm looking for could look like this:

Code:
DATE       | NB_LOGINS_ROLE_A | NB_LOGINS_ROLE_B
-----------|------------------|-----------------
01/06/2005 | 65               | 45
31/05/2005 | 87               | 128
30/05/2005 | 111              | 0

For a given day, it is very possible to have no login of role A, or B, or both A and B (i.e. no entry in the HABILIT table for that/these role(s) for that day).

I'm not a crack in SQL. If someone could give me this query, I would be very grateful to him.


Info: the DB server involved is Oracle 8.
 
Hi, PanzerKunst,

Perhaps:

SELECT date, COUNT(nb_logins_role_a), COUNT(nb_logins_role_b)
FROM habilit
GROUP BY date
ORDER BY date DESC

Regards,

William Chadbourne
Oracle DBA
 
NB_LOGINS_ROLE_A and NB_LOGINS_ROLE_B aren't columns of the HABILIT table. This table has the 3 columns LOGIN_DATE (date), LOGIN (varchar2) and ROLE (varchar2).

Therefore, a "count(<SOMETHING>)" must be used with a "group by LOGIN_DATE" (formatted as 'DD/MM/YYYY').

Hope it helps clarify the problem...
 
with temp(LOGIN_DATE,NB_LOGINS_ROLE_A,NB_LOGINS_ROLE_B)
as
(select LOGIN_DATE,
case ROLE when 'A' then LOGIN end NB_LOGINS_ROLE_A,
case ROLE when 'b' then LOGIN end NB_LOGINS_ROLE_B
from HABILIT
)
select LOGIN_DATE,count(NB_LOGINS_ROLE_A) NB_LOGINS_ROLE_A, count(NB_LOGINS_ROLE_B) NB_LOGINS_ROLE_B
from temp
group by LOGIN_DATE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top