簡體   English   中英

Oracle SQL查詢聯接同一表

[英]Oracle SQL query joining same table

我有一張這樣的桌子:

                 items
id            old_new     object 

1               o         pen
2               n         house
3               o         dog
4               o         cat
5               n         carrot

我想要選擇返回:

id    new_object     old_object

1        null          pen
2        house        null
3        null         dog
4        null         cat  
5        carrot       null 

我是否需要在同一張表上使用外部聯接?

無需加入:

select id, 
       case when old_new = 'n' then object end as new_object,
       case when old_new = 'o' then object end as old_object
from the_table
order by id;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM