读书人

把纵列的雷同数据分组成不同的横列

发布时间: 2012-07-16 15:44:59 作者: rapoo

把纵列的相同数据分组成不同的横列

 select         CARRIERACCOUNDCODE,         max(decode(sectionId, 1,sectionId)) id1,         max(decode(sectionId, 1, setionName)) name1,        max(decode(sectionId, 2,sectionId)) id2,         max(decode(sectionId, 2, setionName)) name2 ,        max(decode(sectionId, 3,sectionId)) id3,         max(decode(sectionId, 3, setionName)) name3,        max(decode(sectionId, 4,sectionId)) id4,        max(decode(sectionId, 4, setionName)) name4,                 max(decode(sectionId, 5,sectionId)) id5,        max(decode(sectionId, 5, setionName)) name5,                 max(decode(sectionId, 6,sectionId)) id6,        max(decode(sectionId, 6, setionName)) name6from (        select             CARRIERACCOUNDCODE,             setionName,            sectionId,            row_number() over(partition by CARRIERACCOUNDCODE order by sectionId) rn,             count(*) over(partition by CARRIERACCOUNDCODE) cnt         from (SELECT t2.CARRIERACCOUNDCODE,                        t2.sectionId,                        t2.setionName                FROM    carrier t1                     LEFT JOIN                        funcinfo t2                     ON t1.CARRIERACCOUNTCODE = t2.CARRIERACCOUNDCODE                      where CARRIERACCOUNDCODE is not null                 )        )       group by CARRIERACCOUNDCODE;     

?

读书人网 >其他数据库

热点推荐