1

I have a data like this

TYPE  RANGE               SALES
A     20180301-20180101     100
A     20171201-20171031   150 
A     20170930-20170731    100
B     20180301-20180101    200
B     20171201- 20171031   200

i want output like this

TYPE 20180301-20180101   20171201-20171031 20170930-20170731
A      100                   150               100

I tried like this

SELECT
FROM
(
SELECT TYPE,MONTH_RANGE,SALES
FROM TABLE
)
pivot
(
    SUM(SALES)
    FOR (MONTH_RANGE) IN (SELECT DISTINCT MONTH_RANGE FROM TABLE)
)

and tried this as well

pivot xml (SUM(SALES) for (month_range) in (SELECT DISTINCT MONTH_RANGE FROM TABLE))

I want this month range to be dynamic not like for month_range in ('20180301-20180101')

Tpk43
  • 363
  • 1
  • 5
  • 23
  • Unfortunately, if you replace the hard coded `IN clause` with a subquery, you'd need a `XML` keyword, but that doesn't bring in the format you want. I think, Oracle needs to work more for dynamic`pivot` clause. – Barbaros Özhan Apr 26 '18 at 07:44

0 Answers0