admin管理员组文章数量:1397175
I have:
SELECT [2, 0, 7] AS transaction_day,
[7, 10, 14] AS revenue_on_transaction_day,
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] AS all_days
I want to get an array mapped based on [all_days] where days with revenue will have a value and other days will be 0:
[10, 0, 7, 0, 0, 0, 0, 14, 0, 0]
I have:
SELECT [2, 0, 7] AS transaction_day,
[7, 10, 14] AS revenue_on_transaction_day,
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] AS all_days
I want to get an array mapped based on [all_days] where days with revenue will have a value and other days will be 0:
[10, 0, 7, 0, 0, 0, 0, 14, 0, 0]
Share
Improve this question
edited Mar 27 at 3:52
vladimir
15.3k3 gold badges51 silver badges80 bronze badges
asked Mar 26 at 19:57
Anastasiya MysiukAnastasiya Mysiuk
1
1 Answer
Reset to default 0Try this way:
WITH
[2, 0, 7] AS transaction_day,
[7, 10, 14] AS revenue_on_transaction_day,
0 AS default_revenue,
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] AS all_days,
mapFromArrays(transaction_day, revenue_on_transaction_day) AS map_of_tr_days
SELECT
arrayMap(
x -> mapContains(map_of_tr_days, x) ? map_of_tr_days[x] : default_revenue,
all_days) AS result
/*
┌─result──────────────────┐
1. │ [10,0,7,0,0,0,0,14,0,0] │
└─────────────────────────┘
*/
本文标签: ClickhouseMap an array based on array with indexes and array with valuesStack Overflow
版权声明:本文标题:Clickhouse - Map an array based on array with indexes and array with values - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744128245a2592053.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论