오라클 쿼리 행 -> 열 변환

POS 값을 기준으로 행을 열로 변환하는 쿼리 (오라클 기준)

select a.creation_date,
max(decode(pos,’0′,keywords)) as 키워드1,
max(decode(pos,’1′,keywords)) as 키워드2,
max(decode(pos,’2′,keywords)) as 키워드3,
max(decode(pos,’3′,keywords)) as 키워드4,
max(decode(pos,’0′,u_file_list)) as 첨부1,
max(decode(pos,’1′,u_file_list)) as 첨부2,
max(decode(pos,’2′,u_file_list)) as 첨부3,
max(decode(pos,’3′,u_file_list)) as 첨부4,
a.u_packageid
from a, b
where a.content_id = b.content_id
and creation_date >= ‘20141104’
group by u_packageid, a.creation_date

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s