I need some help to modify the following query
QUERY I
Select distinct
trunc(sessions.starttime) as date,
comp.CompanyID,
comp.HC,
sessions.userid
from
S_USERSESSION sessions,
S_USER users,
S_COMPANY comp
where
sessions.userid = users.userid and
users.companyid = comp.companyid and
sessions.starttime > trunc(sysdate) - 10
group by
date,sessions.userid,comp.CompanyID,comp.HC,sessions.userid
OUTPUT FROM QUERY I
Date companyID HC userid
2005-11-29 A000 107 10001
2005-11-29 A000 107 10001
2005-11-29 D000 107 20000
2005-11-29 c000 null 3000
2005-11-29 c000 null 3000
2005-8-26 B000 null 0002
2005-8-26 B000 null 0003
2005-8-26 B000 null 0003
If the field HC is not equal Null then this company will be considered as DEALER in the other case
the company WILL BE CONSIDERED AS CLIENT.
Distinct has to be apply if CompanyID has the same date. Also Distinct needs to be apply for userid in case
a usersid has the same date and company.
The final result should be like this...
Results
StartTime Cliente Dealer USERIDS
2005-11-29 1 2 3
2005-8-29 1 0 2
Any help will be apreciate it.
QUERY I
Select distinct
trunc(sessions.starttime) as date,
comp.CompanyID,
comp.HC,
sessions.userid
from
S_USERSESSION sessions,
S_USER users,
S_COMPANY comp
where
sessions.userid = users.userid and
users.companyid = comp.companyid and
sessions.starttime > trunc(sysdate) - 10
group by
date,sessions.userid,comp.CompanyID,comp.HC,sessions.userid
OUTPUT FROM QUERY I
Date companyID HC userid
2005-11-29 A000 107 10001
2005-11-29 A000 107 10001
2005-11-29 D000 107 20000
2005-11-29 c000 null 3000
2005-11-29 c000 null 3000
2005-8-26 B000 null 0002
2005-8-26 B000 null 0003
2005-8-26 B000 null 0003
If the field HC is not equal Null then this company will be considered as DEALER in the other case
the company WILL BE CONSIDERED AS CLIENT.
Distinct has to be apply if CompanyID has the same date. Also Distinct needs to be apply for userid in case
a usersid has the same date and company.
The final result should be like this...
Results
StartTime Cliente Dealer USERIDS
2005-11-29 1 2 3
2005-8-29 1 0 2
Any help will be apreciate it.