简体   繁体   中英

Insert aggregated records in Oracle SQL Developer

I have a table with three fields: Date , ID1 , and ID2 which looks like:

Date          ID1     ID2
-------------------------    
20130101      10      20 
20130101      30      40
20130102       5      10
20130102       7      12
20130102       8      20

I want to have one row per each Date/ID. How can I create a table based on the table above, in which there are only two columns: Date and ID ?

ID includes all ID1 and ID2 s from the previous table:

Date          ID 
----------------- 
20130101      10
20130101      20        
20130101      30
20130101      40
20130102       5
20130102      10
20130102       7
20130102      12
20130102       8
20130102      20

A Union. This will not show any possible duplicate Date, ID combinations. If you do want this, use UNION ALL.

SELECT Date, ID1 AS ID FROM MyTable
UNION
SELECT Date, ID2 FROM MyTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM