Oracle 纵表转横表

NAME                  REPORT                                CNT
-------------------- ------------------------------ ----------
admin                 agent_list.rpt                         1
szyn                  general_allsell.rpt                    2
admin                 airpt_prod.rpt                         24
hbky                  pnrd02.rpt                             9
szyn                  allsell.rpt                            20
test1                 PNRchaxun.rpt                          14
hbky                  airline_dep.rpt                        2
test1                 airln_prod.rpt                         66
admin                 airln_prod.rpt                         5





select name, max(case report when 'pnrd03.rpt' then cnt else 0 end) as pnrd03 , max(case report when 'PNRchaxun.rpt' then cnt else 0 end) as PNRchaxun , max(case report when 'seg_prod.rpt' then cnt else 0 end) as seg_prod , max(case report when 'flt_analysis.rpt' then cnt else 0 end) as flt_analysis from tb group by name order by name;



NAME                            PNRD03       PNRCHAXUN  SEG_PROD  FLT_ANALYSIS
-------------------- ----------- --------------- ----------- ------------
admin                            0                0              0            1
hbky                             0                0              0            0
szyn                             2                0              0            0
test1                            0                14             16           0
test3                            0                0              0            0
xnxj                             0                0              0            0

你可能感兴趣的:(oracle)