1

mysql コードがあり、それを Oracle 構文に変換する必要があり、このエラーに直面しました。誰でも私を助けることができますか?

SELECT SUM(T.SEND_UNREAD_DRAFT) SEND_UNREAD_DRAFT, SUM(T.SEND_READ_DRAFT) SEND_READ_DRAFT, 
  SUM(T.SEND_APPROVED) SEND_APPROVED, SUM(T.SEND_COMPLETED) SEND_COMPLETED, 
    SUM(T.SEND_FAILED)SEND_FAILED,SUM(T.RECEIVED_DRAFT)RECEIVED_DRAFT,SUM(T.RECEIVED_APPROVED)RECEIVED_APPROVED, 
            Sum(T.Received_Accepted_Send)Received_Accepted_Send,Sum(T.Received_Rejected_Send)Received_Rejected_Send, Sum(T.Send_Canceled)Send_Canceled 
        FROM 
                 (SELECT 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN (CASE WHEN READ_FLAG = 'N' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) SEND_UNREAD_DRAFT, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN (CASE WHEN READ_FLAG = 'Y' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) SEND_READ_DRAFT, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'APPROVED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_APPROVED, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'COMPLETED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_COMPLETED, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'FAILED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_FAILED, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'CANCELED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_CANCELED, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN 1 ELSE 0 END) ELSE 0 END) RECEIVED_DRAFT, 
            (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'APPROVED' THEN 1 ELSE 0 END) ELSE 0 END) RECEIVED_APPROVED, 
            (CASE WHEN TYPE = 'IN' THEN (CASE WHEN STATUS = 'COMPLETED' THEN (CASE WHEN INVOICE_STATUS = 'ACCEPTED' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) RECEIVED_ACCEPTED_SEND, 
            (CASE WHEN TYPE = 'IN' THEN (CASE WHEN STATUS = 'COMPLETED' THEN (CASE WHEN INVOICE_STATUS = 'REJECTED' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) RECEIVED_REJECTED_SEND 
               From Eis_Invoice_Header      
                  Where Invoice_Date Between  Sysdate()-365 And (sysdate + Interval '3' Month from dual)) as T
4

3 に答える 3

1
  1. クエリselect sysdate + interval '3' month , add_months(sysdate, 3) from dual; は同じです。

  2. クエリで、使用します where invoice_date between sysdate- 365 and sysdate + interval '3' month'

于 2013-08-26T07:27:18.237 に答える
0

以下のクエリを試してください。

SELECT SUM(T.SEND_UNREAD_DRAFT) SEND_UNREAD_DRAFT, 
       SUM(T.SEND_READ_DRAFT) SEND_READ_DRAFT, 
       SUM(T.SEND_APPROVED) SEND_APPROVED, 
       SUM(T.SEND_COMPLETED) SEND_COMPLETED, 
       SUM(T.SEND_FAILED) SEND_FAILED,
       SUM(T.RECEIVED_DRAFT) RECEIVED_DRAFT,
       SUM(T.RECEIVED_APPROVED) RECEIVED_APPROVED, 
       Sum(T.Received_Accepted_Send) Received_Accepted_Send,
       Sum(T.Received_Rejected_Send) Received_Rejected_Send, 
       Sum(T.Send_Canceled) Send_Canceled 
  FROM 
       (SELECT (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN (CASE WHEN READ_FLAG = 'N' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) SEND_UNREAD_DRAFT, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN (CASE WHEN READ_FLAG = 'Y' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) SEND_READ_DRAFT, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'APPROVED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_APPROVED, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'COMPLETED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_COMPLETED, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'FAILED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_FAILED, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'CANCELED' THEN 1 ELSE 0 END) ELSE 0 END) SEND_CANCELED, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'DRAFT' THEN 1 ELSE 0 END) ELSE 0 END) RECEIVED_DRAFT, 
               (CASE WHEN TYPE = 'OUT' THEN (CASE WHEN STATUS = 'APPROVED' THEN 1 ELSE 0 END) ELSE 0 END) RECEIVED_APPROVED, 
               (CASE WHEN TYPE = 'IN' THEN (CASE WHEN STATUS = 'COMPLETED' THEN (CASE WHEN INVOICE_STATUS = 'ACCEPTED' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) RECEIVED_ACCEPTED_SEND, 
               (CASE WHEN TYPE = 'IN' THEN (CASE WHEN STATUS = 'COMPLETED' THEN (CASE WHEN INVOICE_STATUS = 'REJECTED' THEN 1 ELSE 0 END) ELSE 0 END) ELSE 0 END) RECEIVED_REJECTED_SEND 
          From Eis_Invoice_Header   
         WHERE invoice_date BETWEEN add_months(sysdate, -12) --SYSDATE - 365
           AND add_months(sysdate, 3));
于 2013-08-26T07:32:29.133 に答える
0

interval を add_months に、sysdate() を sysdate に変換する必要があります。また、ケースに変更してシンプルにすることもできます。

SELECT SUM(T.SEND_UNREAD_DRAFT) SEND_UNREAD_DRAFT, SUM(T.SEND_READ_DRAFT) SEND_READ_DRAFT, SUM(T.SEND_APPROVED) SEND_APPROVED, SUM(T.SEND_COMPLETED)     SEND_COMPLETED, SUM(T.SEND_FAILED) SEND_FAILED,SUM(T.RECEIVED_DRAFT) RECEIVED_DRAFT,SUM(T.RECEIVED_APPROVED) RECEIVED_APPROVED, Sum(T.Received_Accepted_Send)     Received_Accepted_Send, Sum(T.Received_Rejected_Send) Received_Rejected_Send, Sum(T.Send_Canceled) Send_Canceled 
FROM( 
SELECT CASE WHEN TYPE = 'OUT' and STATUS = 'DRAFT' and READ_FLAG = 'N' THEN 1 ELSE 0 END SEND_UNREAD_DRAFT, CASE WHEN TYPE = 'OUT' and STATUS = 'DRAFT' and     READ_FLAG = 'Y' THEN 1 ELSE 0 END SEND_READ_DRAFT, CASE WHEN TYPE = 'OUT' and STATUS = 'APPROVED' THEN 1 ELSE 0 END SEND_APPROVED, CASE WHEN TYPE = 'OUT' and     STATUS = 'COMPLETED' THEN 1 ELSE 0 END  SEND_COMPLETED, CASE WHEN TYPE = 'OUT' and STATUS = 'FAILED' THEN 1 ELSE 0 END SEND_FAILED, CASE WHEN TYPE = 'OUT' and     STATUS = 'CANCELED' THEN 1 ELSE 0 END SEND_CANCELED, CASE WHEN TYPE = 'OUT' and STATUS = 'DRAFT' THEN 1 ELSE 0 END RECEIVED_DRAFT, CASE WHEN TYPE = 'OUT' and     STATUS = 'APPROVED' THEN 1 ELSE 0 END RECEIVED_APPROVED, CASE WHEN TYPE = 'IN' and STATUS = 'COMPLETED' and INVOICE_STATUS = 'ACCEPTED' THEN 1 ELSE 0 END     RECEIVED_ACCEPTED_SEND, CASE WHEN TYPE = 'IN' and STATUS = 'COMPLETED' and INVOICE_STATUS = 'REJECTED' THEN 1 ELSE 0 END RECEIVED_REJECTED_SEND From     Eis_Invoice_Header Where Invoice_Date Between  Sysdate-365 And add_months(sysdate ,3)
) as T
于 2013-08-26T07:25:00.507 に答える