0

I have below data in a table called data_tab

sn  code
2   101
2    
2   202
5   103
5   
5

How can i query to see result in one row, like

sn  code1  code2   code3
2   101            202
5   103  
Raging Bull
  • 18,593
  • 13
  • 50
  • 55
  • don't have time to write the exact query but this should get you on the way: http://stackoverflow.com/questions/12598120/mysql-pivot-table-query-with-dynamic-columns – Jester Jun 05 '14 at 05:39
  • 1
    Are you talking about `mysql` or `mssql`? Because you have one tab, but in question you telling about different – Uriil Jun 05 '14 at 05:41

1 Answers1

0

Hi This gives the intented output ... take a look here

select sn,
        max(decode(rn,1,code)) as CODE_1
       ,max(decode(rn,2,code)) as CODE_2
       ,max(decode(rn,3,code)) as CODE_3

from
(
select sn,
      code,
      row_number() over (partition by sn order by null ) rn
from test
  )

group by sn
redsoxlost
  • 1,215
  • 5
  • 19
  • 32