如何找到两个数组列的交集
How to find intersection of two array-columns
我有两个数组(Int32)列,有什么方法可以比较它们并得到这两个数组的交集列吗?
我正在考虑 arrayMap 函数,但它似乎是无效的方法。
示例数据:
id col1 col2 col3
1 [1, 2, 3] [2, 3, 5] [2, 3]
...........
SELECT
[1, 2, 3] AS a,
[2, 3, 5] AS b,
arrayIntersect(a, b)
┌─a───────┬─b───────┬─arrayIntersect([1, 2, 3], [2, 3, 5])─┐
│ [1,2,3] │ [2,3,5] │ [3,2] │
└─────────┴─────────┴──────────────────────────────────────┘
我有两个数组(Int32)列,有什么方法可以比较它们并得到这两个数组的交集列吗?
我正在考虑 arrayMap 函数,但它似乎是无效的方法。
示例数据:
id col1 col2 col3
1 [1, 2, 3] [2, 3, 5] [2, 3]
...........
SELECT
[1, 2, 3] AS a,
[2, 3, 5] AS b,
arrayIntersect(a, b)
┌─a───────┬─b───────┬─arrayIntersect([1, 2, 3], [2, 3, 5])─┐
│ [1,2,3] │ [2,3,5] │ [3,2] │
└─────────┴─────────┴──────────────────────────────────────┘