sql - 通过另一列的键值组合一列中的值
问题描述
我需要按一列组合所有值取决于另一列的键。有人可以帮我解决这个问题吗?
这是我的问题的简短示例。
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_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
源数据中调用的列完全不同。但这似乎是您想要做的。
推荐阅读
- google-apps-script - 如何在谷歌文档中用双换行符替换单个换行符
- python - 制作从 seaborn 到 matplotlib 的堆积条形图
- python - 在类构造函数中表达同级嵌套类的类型提示
- system-verilog - 是否可以在 SystemVerilog 中不同的其他 case 语句中包含的 case 语句中使用相同的表达式?
- angular - 重复识别的“IteratorResult”
- java - 冒泡排序二维数组按字母顺序Java
- huawei-mobile-services - 华为地图突然无法加载崩溃
- javascript - Redux api 状态未在 nextjs 中更新
- javascript - 我可以使外部参数与内部参数相同吗?
- html - 尝试预填充表单以编辑包含图像文件字段的产品 - html、ejs、Nodejs、Expressjs