首页 > 解决方案 > 通过另一列的键值组合一列中的值

问题描述

我需要按一列组合所有值取决于另一列的键。有人可以帮我解决这个问题吗?

这是我的问题的简短示例。

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

标签: sql

解决方案


我想你只是想要一个自我加入:

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源数据中调用的列完全不同。但这似乎是您想要做的。


推荐阅读