簡體   English   中英

通過另一列的鍵值組合一列中的值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM