Clickhouse - 输出每个数组项及其索引/位置
Posted
技术标签:
【中文标题】Clickhouse - 输出每个数组项及其索引/位置【英文标题】:Clickhouse - Output each array item and its index/position 【发布时间】:2020-06-19 15:34:22 【问题描述】:在 Clickhouse 中,我有一个数组列。 我可以输出数组中的每个值及其对应的索引/位置(+1)吗?
所以给定 ['c','b','a'] 我想输出
key position
c 1
b 2
a 3
【问题讨论】:
【参考方案1】:select a,i from
(select ['c','b','a'] arr)
array join arr as a, arrayEnumerate(arr) as i
┌─a─┬─i─┐
│ c │ 1 │
│ b │ 2 │
│ a │ 3 │
└───┴───┘
select (arrayJoin(arrayZip(arr, arrayEnumerate(arr))) as x).1 a, x.2 i
from
(select ['c','b','a'] arr)
┌─a─┬─i─┐
│ c │ 1 │
│ b │ 2 │
│ a │ 3 │
└───┴───┘
【讨论】:
非常感谢丹尼斯以上是关于Clickhouse - 输出每个数组项及其索引/位置的主要内容,如果未能解决你的问题,请参考以下文章
获取 NumPy 数组中的连续命中数及其第一个/最后一个索引