我的查询不起作用

时间:2014-01-08 07:07:36

标签: sql oracle plsql oracle-sqldeveloper plsqldeveloper

我花了很多时间才得到正确的结果,但我总是失败。我在代码中找不到什么问题。我还要区分create_time和close_time,以便日期不会重复。请帮助我。

这是我需要的示例输出:

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

这是我的查询:

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;

APP_ACCOUNT.OTRS_TICKET(某些数据)的表格模式

 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

APP_ACCOUNT.OTRS_QUEUE(某些数据)的表格模式

 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

1 个答案:

答案 0 :(得分:2)

检查此查询:

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);

如果这不能解决您的问题,那么请提供两个表和一些示例数据的详细信息,因为我在各种假设下创建了此查询。