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!

issue with unpivot

user10403630Oct 17 2011 — edited Oct 17 2011
Hi,

I am trying to convert one column into multiple rows using UNPIVOT, and I am able to do it. But now, I am filtering the rows that needs to be converted into rows by joining another table. but its not working. Please find below query.
  SELECT dmdunit,
         dmdgroup,
         loc,
         fcstid,
         MODEL,
         dmdcal,
         period,
         nvl(lag(startdate+(vnum*7),1) over (PARTITION by dmdunit,loc order by dmdunit,loc,vnum),startdate)startdate,
         nvl(lag(startdate+(vnum*7),1) over (PARTITION by dmdunit,loc order by dmdunit,loc,vnum),startdate)+6 enddate,
         qty
         FROM
          (SELECT  dmdunit,
                       dmdgroup,
                       loc,
	   startdate ,
	 startdate enddate, 
	type,
                   qty,
	period,
	fcstid,
	model,
	dmdcal,
	ROW_NUMBER() OVER (PARTITION BY dmdunit,loc ORDER BY TO_NUMBER(SUBSTR(period,7)))vnum
	FROM fcstwide fw,table2 t2
	UNPIVOT INCLUDE NULLS
	( qty FOR( period ) IN
	 ( 
	PERIOD1   AS 'PERIOD1',
	PERIOD2   AS 'PERIOD2',
	PERIOD3   AS 'PERIOD3',
	PERIOD4   AS 'PERIOD4',
	PERIOD5   AS 'PERIOD5'
	)
	)
	WHERE    fw.dmdunit = t2.dmduinit
            
        )ORDER BY dmdunit,loc  
Does this work? I am getting error.

Edited by: BluShadow on 17-Oct-2011 15:45
added {noformat}
{noformat} tags. Please read {message:id=9360002} to learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 14 2011
Added on Oct 17 2011
3 comments
1,069 views