[英]Combining values from one column by the key value from another column
我需要按一列组合所有值取决于另一列的键。 有人可以帮我解决这个问题吗?
这是我的问题的简短示例。
CUST_ID CUST_REL_ID
100 1
100 2
100 3
100 4
200 5
200 6
200 7
CUST_ID CUST_REL_ID
1 1
1 2
1 3
1 4
2 1
2 2
2 3
2 4
...
5 5
5 6
5 7
这是一个简单的连接:
select t1.cust_id cust_id1, t1.cust_rel_id, t2.cust_id cust_id2
from table1 t1
inner join table2 t2 on t1.cust_rel_id = t2.cust_rel_id
我想你只是想要一个自我加入:
select t1.cust_rel_id, t2.cust_rel_id
from t t1 join
t t2
on t1.cust_id = t2.cust_id
order by t1.cust_rel_id, t2.cust_rel_id;
我不明白你的命名约定。 结果集中名为cust_id
的列与源数据中名为cust_id
的列完全不同。 但这似乎是您想要做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.