文章分类 其他 clickhouse 数据库 阅读数 : 414 阅读时长 : 9分钟
select * from tmp_20230608;
1,a,aa
1,b,bb
1,a,aa
2,a,aa
2,b,bb
select id
,groupArray(type) -- 聚合为数组
from tmp_20230608
group by id;
2,"[a, b]"
1,"[a, b, a]"
select \* from tmp\_20230608;
1,a,aa
1,b,bb
1,a,aa
2,a,aa
2,b,bb
select id
,groupUniqArray(type) -- 聚合为去重数组
from tmp\_20230608
group by id;
2,"\[a, b]"
1,"\[a, b]"
select arrayDistinct(\[1,2,3,1,2])
\[1, 2, 3]
select arrayUniq(\[1,2,3,1,2])
3
select arrayCompact(\[1,2,3,3,2,1])
\[1, 2, 3, 2, 1]
select arrayJoin(\[1,2,3])
1
2
3
select arrayFilter(x -> x >= 2,\[1,2,3])
\[2, 3]
select arrayEnumerate(\[11,22,33])
\[1, 2, 3]
select arrayEnumerateDense(\[11,22,33,22])
\[1, 2, 3, 2]
select arrayReduce('min',\[11,22,33]),arrayMin(\[11,22,33]) -- 11,11
select arrayReduce('max',\[11,22,33]),arrayMax(\[11,22,33]) -- 33,33
select arrayReduce('avg',\[11,22,33]),arrayAvg(\[11,22,33]) -- 22,22
select hasAny(\[11,22,33,22],\[44,55]),hasAny(\[11,22,33,22],\[33,55])
0,1
select hasAll(\[11,22,33,22],\[44,55]),hasAll(\[11,22,33,22],\[33,11])
0,1
select arrayWithConstant(5,2)
\[2, 2, 2, 2, 2]
select has(\[11,33,22,44,55],11),has(\[11,33,22,44,55],111)
1,0
select arrayExists(x -> x \* 2 < 50,\[11,33,22,44,55]),arrayExists(x -> x \* 2 > 500,\[11,33,22,44,55]);
1,0
select arrayMap(x -> x \* 10,\[11,33,22,44,55]);
\[110, 330, 220, 440, 550]
select arrayStringConcat(\[1,2,3],'-')
1-2-3
select arraySlice(\[11,22,33,44,55],2,3),arraySlice(\[11,22,33,44,55],-3,2)
\[22, 33, 44],\[33, 44]
select arraySort(\[11,33,22,44,55])
\[11, 22, 33, 44, 55]
select arrayReverseSort()(\[11,33,22,44,55])
\[55, 44, 33, 22, 11]
select arrayPushFront()(\[11,33,22,44,55],8)
\[8, 11, 33, 22, 44, 55]
select arrayPushBack()(\[11,33,22,44,55],8)
\[11, 33, 22, 44, 55, 8]
select arrayPopFront()(\[11,33,22,44,55])
\[33, 22, 44, 55]
select arrayPopBack()(\[11,33,22,44,55])
\[11, 33, 22, 44]
select arrayDifference()(\[11,33,22,44,55])
\[0, 22, -11, 22, 11]
select runningDifference(arrayJoin()(\[11,33,22,44,55]))
0
22
\-11
22
11
select toTypeName(CAST('2023-01-01 01:02:03' AS DateTime))
DateTime
select toColumnTypeName(CAST('2023-01-01 01:02:03' AS DateTime))
Const(UInt32)
select defaultValueOfTypeName('Date')
1970-01-01
-- 结合coalesce自动处理表中的null值
select coalesce(`${column},
defaultValueOfTypeName(if(startsWith(toTypeName($`{
column}), 'Nullable'),
substr(toTypeName(`${column}), 10,
char_length(toTypeName($`{
column})) - 10),
toTypeName(`${column}))))
from $`{
table};
更多【clickhouse-【总结卡】clickhouse数据库常用高级函数】相关视频教程:www.yxfzedu.com