Showing posts with label Pivot example SQL Unpivot. Show all posts
Showing posts with label Pivot example SQL Unpivot. Show all posts

Wednesday, October 21, 2009

A unpivot example (three rows into X rows ) with SQL

I have the following information :

OOO 1 2 3
--- - - -
 A  X X
 B  X   X
 C    X X

And I want this as output:

000   print
---   -----
 A      1
 A      2
 B      1
 B      3
 C      2
 C      3

 This can be done with the following SQL statement: