tags:

views:

29

answers:

1

Need some help about data pivoting in SQL.

I have a Table which has the following data

(Job Operation Material)
(1    10        a)
(1    20        a)
(1    20        b)
(2    10        c)

I want to pivot and display it as

(Job Material Oper1 Oper2 Oper3)
(1    a        10    null  null)
(1    b        null  20    null)
(2    c        10    null   null.)

How to archive the above result.

A: 
 select JOB
      , Material
      , if(Operation = 10), Operation , null) as Oper1
      , if(Operation=20,Operation,null) as Oper2
      , null as Oper3
 from "I have a Table"
lexu