I'm newbie in Oracle SQL. I tried to display Name of tickets, No. of close and open tickets and the date. But I can't get the right query.
Desired output:
01/20/2014, User management, 20, 15
Query:
SELECT 'Data'
||','||TO_CHAR(D.DTIME_DAY,'MM/dd/yyyy')
||','||q.name -- as ticket
||','||NVL(o.CNT_OPENED,0) --as cnt_opened
||','||NVL(c.CNT_CLOSED,0) --as cnt_closed
FROM OWNER_DWH.DC_DATE d
LEFT JOIN (
SELECT q.name, count(q.name), TRUNC(t.CREATE_TIME) as report_date, count(*) as cnt_opened
FROM APP_ACCOUNT.OTRS_TICKET t
left join app_account.otrs_queue q
ON q.ID = t.QUEUE_ID
WHERE t.CREATE_TIME BETWEEN SYSDATE -7 AND SYSDATE -1
and t.queue_id not in (63, 61, 69, 59, 58, 60, 56, 64, 65, 23, 67, 68, 57)
GROUP BY q.name, TRUNC(t.CREATE_TIME)
) o ON d.DTIME_DAY=o.REPORT_DATE
LEFT JOIN (
SELECT q.name, count(q.name), TRUNC(t.CLOSE_TIME) as report_date,count(*) AS cnt_closed
FROM APP_ACCOUNT.OTRS_TICKET t
left join app_account.otrs_queue q
ON q.ID = t.QUEUE_ID
WHERE t.CLOSE_TIME BETWEEN SYSDATE -7 AND SYSDATE -1
and t.queue_id not in (63, 61, 69, 59, 58, 60, 56, 64, 65, 23, 67, 68, 57)
GROUP BY q.name, TRUNC(t.CLOSE_TIME)
) c ON D.DTIME_DAY=c.REPORT_DATE
WHERE d.DTIME_DAY BETWEEN SYSDATE -7 AND TRUNC(SYSDATE) -1
AND TRUNC(d.DTIME_DAY)= d.DTIME_DAY
ORDER BY D.DTIME_DAY;
And if I want to group the data?
Example: In one column, let's say I have:
E-mail management
E-mail management::Add user e-mail
E-mail management::Add new Outlook distribution list
E-mail management::Add new Outlook shared mailbox
E-mail management::Add new SA e-mail (Zimbra account)
POS::POS issue - need paper
POS::POS issue - internet connection problems
All name that has E-mail management will group as E-mail management and all name that has POS will group as POS.
Desires output:
02/10/2014, E-mail, 4
02/10/2014, POS, 2
How to do that?
Please help me. Thank you in advance.