The diversion of data--becomes compact

Source: Internet
Author: User

The need now is to make the following result sets compact:

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

1
2
3
4
5
6
7
8
9
Ten
One
A


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


the idea is to isolate each column and then make a left connection:
with T1 as (select RowNum rn,col1 from Test where col1 is isn't null),
T2 as (select RowNum rn,col2 from test where col2 are NOT null),
T3 as (select RowNum RN, Col3 from test where col3 are 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

The diversion of data--becomes compact

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.