Microsoft
Software
Hardware
Network
Question : SQL Query for count function on multiple tables
Hello experts - I need to build a SQL query against an Oracle Database (two tables) that would do the following:
- count the number of sucessful hits (authentication success) to a particular application for each day and sorted by Department, Departmentcode, and day of the month.
such that output of the query looks like:
Department code Day Portal App1 App2
Marketting 36 YY-MM-DD 134 54 89
Finance 16 YY-MM-DD 3 5 3
Development 12 YY-MM-DD 3 76 0
There are two tables of interest one that contains the audit information (audit) and the other that contains the department information (user).
Here is the audit table information:
CREATE TABLE AUDIT
( "EVENTDATEANDTIME" TIMESTAMP (6),
"SERVERID" NVARCHAR2(255),
"EVENTNAME" NVARCHAR2(255),
"URL" NVARCHAR2(255),
"OPERATION" NVARCHAR2(255),
"TARGETUSERDN" NVARCHAR2(255),
"IPADDRESS" NVARCHAR2(255),
"USERPROFILEATTRS" NVARCHAR2(255),
)
The sample data from audit table looks like this:
EVENTDATEANDTIME = 18-AUG-10 07.33.01.000000000 PM
SERVERID = myserver1
EVENTNAME = AUTHN_SUCCESS
URL = xyz.mydomain.com%2Fportal%
2Flang%2Fe
n-us%2defa
ult.aspx
OPERATION = GET
TARGETUSERDN = uid=markuser1,ou=people,o=
mycomany,c
=com
IPADDRESS = 10.8.146.134
USERPROFILEATTRS = uid=markuser1
EVENTDATEANDTIME = 19-AUG-10 05.30.09.000000000 PM
SERVERID = myserver2
EVENTNAME = AUTHN_SUCCESS
URL = xyz.mydomain.com%2FAPP1%2F
lang%2Fen-
us%2defaul
t.aspx
OPERATION = GET
TARGETUSERDN = uid=finuser1,ou=people,o=m
ycomany,c=
com
IPADDRESS = 10.8.146.130
USERPROFILEATTRS = uid=finuser1
Here is the sample user table information:
CREATE TABLE user
( userid varchar2(50) not null,
department_name varchar2(50) not null,
department_code number(6) not null,
)
The sample data from user table looks like this:
userid = markuser1
Department_name = Marketting
Department_code = 36
userid = finuser1
Department_name = Finance
Department_code = 12
Thanks,
Answer : SQL Query for count function on multiple tables
try this :
select
department_name,
department_code, day,
sum(succ_por_count) Portal,
sum(succ_app1_count) App1,
sum(succ_app2_count) App2
from (
select u.department_name, u.department_code, to_char(eventdateandtime,'
yy-mm-dd')
Day,
case when EVENTNAME = 'AUTHN_SUCCESS' and url like '%portal%' then 1 else 0 end succ_por_count,
case when EVENTNAME = 'AUTHN_SUCCESS' and url like '%APP1%' then 1 else 0 end succ_app1_count,
case when EVENTNAME = 'AUTHN_SUCCESS' and url like '%APP2%' then 1 else 0 end succ_app2_count
from user_tbl u, audit_tbl a
where u.userid = substr(USERPROFILEATTRS,5)
order by u.department_name, u.department_code, to_date(to_char(eventdatea
ndtime,'yy
-mm-dd'),'
yy-mm-dd')
)
group by department_name, department_code, day
Random Solutions
Exchange 2003 Event 116
Convert 16bpp bitmap to 32bpp or to JPEG on Windows Mobile 5.0 onwards
Exchange Server 2010 Delegate Access
Is there a way to use visual basic 6 to write data directly to a cd or dvd for windows, xp, vista and 7
Can't install wifi printer MX870
No Networking Installed on Windows 2008 VM After Migrating From VMWARE Server to ESXi Server
Display logon message to new users at first logon.
Sysprep failed to set computername
Assigning values to a range of cells in Excel with VBA
Computer boots only so often