简体   繁体   English

通过另一列的键值组合一列中的值

[英]Combining values from one column by the key value from another column

I need to combine all values by one column depends on the key from another column.我需要按一列组合所有值取决于另一列的键。 Can someone help me to get out of this problem please?有人可以帮我解决这个问题吗?

here is the short example of my problem.这是我的问题的简短示例。

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

That's a simple join:这是一个简单的连接:

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

I think you just want a self-join:我想你只是想要一个自我加入:

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;

I don't understand your naming conventions.我不明白你的命名约定。 The column called cust_id in the result set looks nothing like the column called cust_id in the source data.结果集中名为cust_id的列与源数据中名为cust_id的列完全不同。 But this appears to be what you want to do.但这似乎是您想要做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM