我正在尝试在表中创建一个新列,其内容基于现有列对的值。 特别是如果我有表格(ID不是主键)
ID | Value | New Column(The column I want)
1 A A:apple
1 B A:orange
2 apple B:apple
2 orange B:orange
我是SQL的新手,所以这里的任何见解都会非常有用。
顺便说一下,如果重要的话,我会使用Oracle。
其他详细信息:我希望配对值:基于其ID不匹配的事实值
答案 0 :(得分:2)
假设您希望ID1的所有值与ID2的所有值配对,您可以将表交叉连接到自身,但过滤ID:
select t1.value ||':'|| t2.value
from my_table t1
cross join my_table t2
where t1.id = 1
and t2.id = 2;
答案 1 :(得分:2)
SQL小提琴是here
select t1.value||':'||t2.value
from mytable t1
cross join
mytable t2
where t1.id = 1
and t2.id = 2