2013-06-21 4 views

답변

5

당신은 결과를 얻을 수 row_number()와 함께 PIVOT 기능을 사용할 수있는 값이되어야 col_2에는 새로운 테이블 요소의 열 이름이되어야 :

select A, B 
from 
(
    select col_1, col_2, 
    row_number() over(partition by col_1 order by col_2) rn 
    from yourtable 
) d 
pivot 
(
    max(col_2) 
    for col_1 in (A, B) 
) piv; 

SQL Fiddle with Demo을 참조하십시오.

또는 당신은 열로 행을 변환 할 경우 표현식으로 집계 함수를 사용할 수 있습니다

select 
    max(case when col_1 = 'A' then col_2 end) A, 
    max(case when col_1 = 'B' then col_2 end) B 
from 
(
    select col_1, col_2, 
    row_number() over(partition by col_1 order by col_2) rn 
    from yourtable 
) d 
group by rn; 

매우 형제 SQL Fiddle with Demo

+1

감사를 참조 ............ .. –

관련 문제