解决方案 »

  1.   


    --构造三个表数据
    with tab1 as
     (select 201406001 code, 836.00 c1
        from dual
      union all
      select 201406001, 0.00
        from dual),
    tab2 as
     (select 201406001 code, '现金' c4, 36.00 c5
        from dual
      union all
      select 201406001, '银联', 800.00
        from dual),
    tab3 as
     (select 201406001 code, '足浴' c6, 180 c7
        from dual
      union all
      select 201406001, '按摩', 380
        from dual
      union all
      select 201406001, '桑拿', 276
        from dual)
    --查询sql
    select t1.code, t1.c1, t2.c4, t2.c5, t3.c6, t3.c7
      from (select code, c1, row_number() over(partition by code order by c1) rn
              from tab1) t1
      full join (select code,
                        c4,
                        c5,
                        row_number() over(partition by code order by c5) rn
                   from tab2) t2
        on t1.code = t2.code
       and t1.rn = t2.rn
      full join (select code,
                        c6,
                        c7,
                        row_number() over(partition by code order by c7) rn
                   from tab3) t3
        on t1.code = t3.code
       and t1.rn = t3.rn
    查询结果