The basic idea here is to use Max, because the rest of the columns are null, so Max can finally get the value of this line.
Common query:
SELECT ICD, CaseWhen (Row_number () + (PARTITION by Inner_cd ORDER by Slide_seq))=1Then Slide_qty END asSlide_qty1, CaseWhen (Row_number () over (PARTITION by Inner_cd ORDER by Slide_seq))=1Then Slide_s_unit_price END asSlide_s_unit_price1, CaseWhen (Row_number () over (PARTITION by Inner_cd ORDER by Slide_seq))=2Then Slide_qty END asSlide_qty2, CaseWhen (Row_number () over (PARTITION by Inner_cd ORDER by Slide_seq))=3Then Slide_qty END asSlide_qty3from"Temp"."User"Mmwhere Mm.icd='addm01-20160612-1-100002-001'
The data obtained are:
After using Max:
SELECT MAX ( CaseWhen slide_seq =1Then Slide_qty END) asslide_qty1, MAX ( CaseWhen slide_seq =2Then Slide_qty END) asSlide_qty2, MAX ( CaseWhen slide_seq =3Then Slide_qty END) asSlide_qty3, MAX ( CaseWhen slide_seq =4Then Slide_qty END) asSlide_qty4, MAX ( CaseWhen slide_seq =5Then Slide_qty END) asslide_qty5, MAX ( CaseWhen slide_seq =6Then Slide_qty END) asSlide_qty6, MAX ( CaseWhen slide_seq =7Then Slide_qty END) asSlide_qty7, MAX ( CaseWhen slide_seq =8Then Slide_qty END) asSlide_qty8, MAX ( CaseWhen slide_seq =9Then Slide_qty END) asSlide_qty9, MAX ( CaseWhen slide_seq =TenThen Slide_qty END) asSlide_qty10fromuserwhere anken_id='addm01-20160612-1-100002-001'
The results obtained:
It can then be combined by a subquery
SELECT * fromm_product INNER JOIN (SELECT anken_id, ICD, MAX ( CaseWhen slide_seq =1Then Slide_qty END) asslide_qty1, MAX ( CaseWhen slide_seq =2Then Slide_qty END) asSlide_qty2, MAX ( CaseWhen slide_seq =3Then Slide_qty END) asSlide_qty3, MAX ( CaseWhen slide_seq =4Then Slide_qty END) asSlide_qty4, MAX ( CaseWhen slide_seq =5Then Slide_qty END) asslide_qty5, MAX ( CaseWhen slide_seq =6Then Slide_qty END) asSlide_qty6, MAX ( CaseWhen slide_seq =7Then Slide_qty END) asSlide_qty7, MAX ( CaseWhen slide_seq =8Then Slide_qty END) asSlide_qty8, MAX ( CaseWhen slide_seq =9Then Slide_qty END) asSlide_qty9, MAX ( CaseWhen slide_seq =TenThen Slide_qty END) asslide_qty10 from Userwhere user.anken_id='addm01-20160612-1-100002-001'GROUP by user.inner_cd,user.anken_id) T1 on m_product.anken_id=t1.anken_idwheret1.anken_id ='addm01-20160612-1-100002-001'
You can get rich row-to-column data.
PostgreSQL row to column after adding to a whole data