0

I tried many time to get the right result but I'm always fail. I can't find what's wrong in my codes. I want also to distinct the create_time and close_time, so that the date will not repeat.Please help me.

This is the sample output that I need:

ID         NAME      CREATE_TIME     CREATEDCOUNT    CLOSE_TIME   CLOSEDCOUNT     

1          POS        01-JAN-14           1           01-JAN-14      1
2          EMAIL      02-JAN-14           10          02-JAN-14     10

THIS IS MY QUERY:

SELECT t.create_time, t.queue_id, q.name
FROM APP_ACCOUNT.OTRS_TICKET t
LEFT JOIN APP_ACOUNT.OTRS_QUEUE q
ON t.queue_id = q.id
WHERE t.CREATE_TIME BETWEEN SYSDATE -7 AND SYSDATE
GROUP BY trunc(t.create_time), t.queue_id, q.name
ORDER BY trunc(t.create_time), t_id, q.name;

THE TABLE SCHEMA FOR APP_ACCOUNT.OTRS_TICKET (some data)

 ID TITLE                         QUEUE_ID ... .... .... .... ....  ....  ....        CREATE_TIME   .... .... CLOSE_TIME ..... ..... 

 39 Cannot access the Zimbra Email 11      5     1     3   2  hcph  hcph  POS-generic 15-OCT-13       5    \N  15-OCT-13 5    Office 
 40 Slow WIFI Connection           21      5     1     3   2  hcph  hcph  POS-generic 15-OCT-13       5    \N  15-OCT-13 5    Office 
 41 Change phone number in IDM      7      5     1     3   2  hcph  hcph  hcphuser   15-OCT-13       5    \N 15-OCT-13  5    Office

TABLE SCHEMA FOR APP_ACCOUNT.OTRS_QUEUE (SOME DATA)

 ID      NAME
 58 Facilities and Procurement::Office Furniture Request
 59 Facilities and Procurement::Supplies Request ��� Marketing & Sales
 60 Facilities and Procurement::Supplies Request ��� Office Supplies
 2  Raw
 66 Procurement::Supplies Request - Office Supplies
5
  • 1
    What is your expected output?
    – San
    Jan 8, 2014 at 7:09
  • @San i already mention above Jan 8, 2014 at 7:10
  • why are you using trunc
    – zzlalani
    Jan 8, 2014 at 7:11
  • give table schema and some sample data tooo
    – Dhaval
    Jan 8, 2014 at 7:12
  • Please do mention the tables involved. Jan 8, 2014 at 7:22

1 Answer 1

2

Check this query:

SELECT t.queue_id, 
       q.name,  
       trunc(t.create_time), 
       count(t.create_time) createcount,  
       trunc(t.close_time), 
       count(t.close_time) closedcount, 
  FROM APP_ACCOUNT.OTRS_TICKET t
       LEFT JOIN APP_ACOUNT.OTRS_QUEUE q
       ON t.queue_id = q.id
 WHERE t.CREATE_TIME BETWEEN SYSDATE -7 AND SYSDATE
 GROUP BY trunc(t.create_time), t.queue_id, q.name, trunc(t.close_time);

If this doesn't solves your problem then give the details of both tables and some sample data because I created this query on various assumptions.

8
  • I receive an error -- ORA-00942: table or view does not exist 00942. 00000 - "table or view does not exist" Jan 8, 2014 at 7:38
  • 1
    @user3172075 - this query copies your original in having two schema names; APP_ACCOUNT and APP_ACOUNT (with one C). Presumably that's a mistake in your original code. That should have been pretty obvious from the error message, surely.
    – Alex Poole
    Jan 8, 2014 at 7:49
  • oh sorry i didn't notice. the query is now running correctly. I have a question. I have another query similar in the question but when I run it the create_time and close_time have a duplicate. What's wrong? Jan 8, 2014 at 7:53
  • @user3172075 : Probably you are using wrong column list in the group by clause.
    – San
    Jan 8, 2014 at 7:57
  • how come? here's my query: SELECT trunc(create_time), COUNT() CreatedCount, trunc(close_time), COUNT() CloseCount FROM APP_ACCOUNT.OTRS_TICKET WHERE CREATE_TIME BETWEEN SYSDATE -7 AND SYSDATE AND CLOSE_TIME BETWEEN SYSDATE -7 AND SYSDATE GROUP BY trunc(create_time), trunc(close_time) ORDER BY trunc(create_time), trunc(close_time); Jan 8, 2014 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.