上个月的本周数据

时间:2020-08-11 10:02:18

标签: oracle11g

我有前一周的销售量

SELECT PARTICULARS,
       (TO_CHAR(FROMDT) || '  to  ' || TO_CHAR(TODT)) "Date",
       SUM(BILLS) Bills,
       ROUND(SUM(TOTAL_EXCULDING_OF_TAX) / SUM(BILLS), 2) "Avg Bills",
       SUM(TOTAL_EXCULDING_OF_TAX) "Total Excluding Of Tax",
       SUM(TOTAL_INCULDING_OF_TAX) "Total Including Of Tax"
  FROM (SELECT 'Previous Week Sales' PARTICULARS,
               TO_CHAR(TRUNC(TO_DATE(:TODT), 'IW') - 1) TODT,
               TO_CHAR(TRUNC(TO_DATE(:TODT), 'IW') - 7) FROMDT,
               SUM(NVL(H.BASICAMT, 0) - NVL(H.CASHDISCAMT, 0) -
                   NVL(H.REFUNDAMT, 0)) TOTAL_EXCULDING_OF_TAX,
               SUM(NVL(H.BILLAMT, 0)) TOTAL_INCULDING_OF_TAX,
               COUNT(T.TRANHID) BILLS
          FROM TRANH T, INVOICECASHSALES_H H
         WHERE T.TRANHID = H.TRANHID
           AND T.DT <= TO_CHAR(TRUNC(TO_DATE(:TODT), 'IW') - 1)
           AND T.DT >= TO_CHAR(TRUNC(TO_DATE(:TODT), 'IW') - 7)
           AND T.DOCSTATUSID IN (0, 1)
           AND T.ISDOCNOASSIGN = 1
           AND T.TRNTYPEID = 8
           AND T.COMPANYID = :COMPANYID)
 GROUP BY PARTICULARS, FROMDT, TODT

0 个答案:

没有答案