The new
For example we have data in such a format:-
SQL> Select * from (.....)
To aggregate Data in columns we can use Pivot operator in Oracle as follows:-
SQL>Select * from (.....)PIVOT(
Max(Time_Diff)
FOR Pivot_For in ('First' as First, 'Second' as Second, 'Third' as Third, 'Fourth' as Fourth)
)
PIVOT
operator in 11g takes data in separate rows, aggregates it and converts it into columns:-For example we have data in such a format:-
SQL> Select * from (.....)
Name | Time_Diff | Pivot_For |
A | 0 0:0:0.0 | First |
A | 0 0:0:2.428 | Second |
A | 0 0:0:5.548 | Third |
A | 0 0:1:1.991 | Fourth |
B | 0 0:2:0.0 | First |
B | 0 0:0:3.428 | Second |
B | 0 0:0:5.248 | Third |
B | 0 0:2:3.991 | Fourth |
C | 0 1:2:0.0 | First |
C | 0 2:0:3.428 | Second |
C | 0 3:0:5.248 | Third |
C | 0 0:45:3.991 | Fourth |
To aggregate Data in columns we can use Pivot operator in Oracle as follows:-
SQL>Select * from (.....)PIVOT(
Max(Time_Diff)
FOR Pivot_For in ('First' as First, 'Second' as Second, 'Third' as Third, 'Fourth' as Fourth)
)
Name | First | Second | Third | Fourth |
A | 0 0:0:0.0 | 0 0:0:2.428 | 0 0:0:5.548 | 0 0:1:1.991 |
B | 0 0:2:0.0 | 0 0:0:3.428 | 0 0:0:5.248 | 0 0:2:3.991 |
C | 0 1:2:0.0 | 0 2:0:3.428 | 0 3:0:5.248 | 0 0:45:3.991 |
Comments
Post a Comment