简体   繁体   English

Oracle SQL查询联接同一表

[英]Oracle SQL query joining same table

I have a table like this: 我有一张这样的桌子:

                 items
id            old_new     object 

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

I would like the select return: 我想要选择返回:

id    new_object     old_object

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

Do I need to use an outer join on the same table? 我是否需要在同一张表上使用外部联接?

No join needed: 无需加入:

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