All Forums General
22 May 2014
Teradata PIVOT function || Equivalence of ORACLE or SQL Server PIVOT function in Teradata

I have a query in SQL server using PIVOT function, samle query working in SQL server like -
select PT.* from (select FName, LName, RDate, Rank from Tab_Ranking)sq
pivot (max(Rank) for RDate in ([2013-08-20], [2013-08-21])) as PT
What would be the equivalent query or presentation in Teradata? Please help.
For further information the date range could be for a year which are the expceted Pivot columns, so selecting seperately in the main select query is not feasible.

Raja_KT 1246 posts Joined 07/09
24 May 2014

Simulate this if it helps you.Since you come from Oracle background, you are quite familiar with emp table.
Next level you can tweak as per your requirement. Hope it helps you.

Oracle pivot (take care of version): SELECT * FROM (SELECT job, deptno, sum(sal) sal FROM emp GROUP BY job, deptno)

         PIVOT ( sum(sal) FOR deptno IN (10, 20, 30, 40) );


The below query runs both in oracle and teradata too.



                sum(CASE WHEN  DEPTNO=10 then SAL else NULL END) DEPT10,

                sum(CASE WHEN  DEPTNO=20 then SAL else NULL END) DEPT20,

                sum(CASE WHEN  DEPTNO=30 then SAL else NULL END) DEPT30,

                sum(CASE WHEN  DEPTNO=40 then SAL else NULL END) DEPT40

           FROM EMP

       GROUP BY job;

Raja K Thaw
My wiki:
Street Children suffer not by their fault. We can help them if we want.

You must sign in to leave a comment.