我有一张这样的表:
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
我是否需要在同一个表上使用外连接?
答案 0 :(得分:2)
不需要加入:
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;