zoukankan      html  css  js  c++  java
  • 引水数据--紧凑

      今天,需求量约为以下结果集紧凑:

             COL1       COL2       COL3
         ---------- ---------- ----------         

             1
             2
             3
             4
             5
             6
                        7
                        8
                        9
                       10
                                  11
                                  12


          COL1       COL2       COL3
        ---------- ---------- ----------
             1          7         11
             2          8         12
             3          9
             4         10
             5
             6

    drop table test;
    create table test(col1 number,col2 number,col3 number);
    insert into test values(1,null,null);
    insert into test values(2,null,null);
    insert into test values(3,null,null);
    insert into test values(4,null,null);
    insert into test values(5,null,null);
    insert into test values(6,null,null);
    insert into test values(null,7,null);
    insert into test values(null,8,null);
    insert into test values(null,9,null);
    insert into test values(null,10,null);
    insert into test values(null,null,11);
    insert into test values(null,null,12);
    commit;

    SQL> select * from test;
          COL1       COL2       COL3
    ---------- ---------- ----------
             1
             2
             3
             4
             5
             6
                        7
                        8
                        9
                       10
                                  11
                                  12


    思路是每列查出来,然后做左连接:
    with t1 as(select rownum rn,col1 from test where col1 is not null),
    t2 as(select rownum rn,col2 from test where col2 is not null),
    t3 as(select rownum rn,col3 from test where col3 is not null)
    select col1,col2,col3 from t1,t2,t3 where t1.rn=t2.rn(+) and t2.rn=t3.rn(+) 
    order by t1.rn;

          COL1       COL2       COL3
    ---------- ---------- ----------
             1          7         11
             2          8         12
             3          9
             4         10
             5
             6

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    SendMessage操作另一个EXE,存在这,以后也许用得着。
    六、Delphi 2009 泛型容器单元(Generics.Collections)[5]: TObject...<T> 系列
    闲扯原码、反码、补码
    限制edit只能输入数字
    动态创建TXMLDocument对XML文件进行读取和写入
    XML操作
    Ubuntu下配置lazarus开发环境
    C#结构体(二)
    【转】 如何有效減少Nios II EDS所編譯程式碼大小? (IC Design) (Nios II)
    关于NiosII和Win7系统兼容性的问题处理方式
  • 原文地址:https://www.cnblogs.com/blfshiye/p/4750664.html
Copyright © 2011-2022 走看看