×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Help needed on SQL request (JOIN + COUNT?)

Help needed on SQL request (JOIN + COUNT?)

Help needed on SQL request (JOIN + COUNT?)

(OP)
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.

RE: Help needed on SQL request (JOIN + COUNT?)

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

RE: Help needed on SQL request (JOIN + COUNT?)

(OP)
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...

RE: Help needed on SQL request (JOIN + COUNT?)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close