Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select Between Month and Year

G.YJun 24 2019 — edited Jun 24 2019

I want to select data in where condition from Month and Year TO Month and Year.

Please guide...

SELECT A.YEAR, (A.MONTH2) as Profit_Month, A.MONTH,

        (SELECT SUM(NVL(INVC_NET_AMOUNT,0))

        FROM INV.PURCHASE_VIEW

        WHERE TO_CHAR(PUR_DATE,'MMRRRR') = A.MONTH

        ) AS TOTAL_PURCHASES,

        A.TOTAL_SALE, A.TOTAL_COST, A.TOTAL_PROFIT,

       ( SELECT sum(Nvl(E.AMOUNT,0))

        from INV.DAILY_EXPENSES_VIEW E

        where  (to_char(E.EXPN_DATE,'MMRRRR') = A.MONTH )

        )AS TOTAL_EXPENSES,

        A.TOTAL_PROFIT -

        ( SELECT sum(Nvl(E.AMOUNT,0))

        from INV.DAILY_EXPENSES_VIEW E

        where  (to_char(E.EXPN_DATE,'MMRRRR') = A.MONTH )

        )AS NET_PROFIT

FROM

(select  

        TO_NUMBER(to_char( p.INVOICE_DATE,'MMYYYY')) as Month,to_char( p.INVOICE_DATE,'Mon.YYYY') as Month2, to_char( p.INVOICE_DATE,'YYYY')  as year,

        sum(nvl(p.INV_NET_AMOUNT,0)) as total_sale,

        sum(nvl(p.TOTAL_COST,0)) as total_cost,

        sum(nvl(p.INV_NET_PROFIT,0)) as total_profit

from    INV.CUSTOMER_INVOICE_WISE_PROFIT p

group by to_char( p.INVOICE_DATE,'MMYYYY') , TO_CHAR( p.INVOICE_DATE,'MM RRRR'), to_char( p.INVOICE_DATE,'Mon.YYYY'), to_char( p.INVOICE_DATE,'YYYY')

) A

ORDER BY A.YEAR, A.MONTH;

This post has been answered by KayK on Jun 24 2019
Jump to Answer
Comments
Post Details
Added on Jun 24 2019
4 comments
4,229 views