-1
Q
数据帧的基础上
A
回答
0
传递特性的想法是选择一个来源,并尝试找到两个目标的传递性。如果那些是相同的,那么你有正确的组合。
我为调试目的添加了额外的列,但查询可以简化一点点。
SELECT *
FROM (
SELECT source.[V1], source.[V2],
target1.[V1] as t1_v1,
target1.[V2] as t1_v2,
target2.[V1] as t2_v1,
target2.[V2] as t2_v2,
CASE WHEN source.[V1] = target1.[V1]
THEN target1.[V2]
ELSE target1.[V1]
END as transitive1,
CASE WHEN source.[V2] = target2.[V2]
THEN target2.[V1]
ELSE target2.[V2]
END as transitive2
FROM A as source
JOIN A as target1
ON (source.[V1] = target1.[V1] OR source.[V1] = target1.[V2])
AND NOT (source.[V1] = target1.[V1] AND source.[V2] = target1.[V2])
JOIN A as target2
ON (source.[V2] = target2.[V1] OR source.[V2] = target2.[V2])
AND NOT (source.[V1] = target2.[V1] AND source.[V2] = target2.[V2])
) T
WHERE T.transitive1 = T.transitive2
输出
为了得到你想要选择正确的列,并添加aditional的过滤结果
SELECT T.[V1] as [V1],
T.[V2] as [V2],
T.[transitive1] as [V3]
....
WHERE T.[V1] > T.[V2]
AND T.[V2] > T.[transitive1]
AND T.transitive1 = T.transitive2
相关问题
- 1. 熊猫:行数为列值的基础上排序数据帧
- 2. 拆分一个多指标数据帧的基础上另据帧
- 3. 在数据帧上的列名的基础添加两列
- 4. 拆分数据帧并写入新的CSV的基础上环
- 5. 熊猫:在数据帧基础上的日期范围和ID
- 6. 数据总结基础上
- 7. 排序一个数据帧基础上多列 - 排序问题
- 8. 如何基于在基础R另一个数据帧
- 9. 显示数据的基础上
- 10. 日期时间基础参数的取数据格式的基础上
- 11. 熊猫:添加新的列在数据帧基础上在列的值
- 12. 切片数据基础上多列
- 13. 基础上的CurrentUICulture
- 14. 基础上的actionPerformed
- 15. 此基础上
- 16. 数据库基础知识
- 17. 的R - 基于从基准数据帧
- 18. 基础上可变
- 19. 基础上多列
- 20. 基于另一个数据帧更改数据帧的值
- 21. 如何在数据帧的基础添加列于其他列的值火花
- 22. WPF数据绑定的基础知识
- 23. 以Rx为基础的数据缓冲
- 24. Uint8Array.buffer数据的基础16编码
- 25. 连接表的基础上,
- 26. MySQL的基础上多列
- 27. 排序键的基础上
- 28. 错误基础上的MacOS
- 29. 失败基础上的Ubuntu
- 30. 总表的基础上表
这是什么逻辑?为什么没有'{1,6,5}' –
因为没有{1,5} – user2999110