clickhouse常用函数

2020-11-29  本文已影响0人  二十赶朝暮__
测试数据表test02:
ca,cb,cc
A,W,1
A,W,2
B,X,1
B,Z,2
B,Z,4
需求:分组取top1
select ca,cb,groupArray(1)(cc) from test02 group by ca,cb
输出结果:
B,Z,[2]
A,W,[1]
B,X,[1]
with (select [100,200,300,200,400,500]) as arr
select arrayEnumerate(arr) as row_number,   
    arrayEnumerateDense(arr) as dense_rank,   
    arrayEnumerateUniq(arr) as uniqu_rank;

输出结果   
row_number     dense_number   unique_number"
[1,2,3,4,5,6]",  "[1,2,3,2,4,5]",   "[1,1,1,2,1,1]"
with (select [100,200,300,200,400,500]) as arr
select arrayDifference(arr)
输出结果
[0,100,100,-100,200,100]
SELECT a, neighbor( a,-1 ) from 
(SELECT arrayJoin( [1,2,3,6,34,3,11] ) as a,'u' as  b)
输出结果
a neighbor(a,-1)
1,0
2,1
3,2
6,3
34,6
3,34
11,3
注:非字符串数组不能拼接
SELECT arrayStringConcat( ['1','2','3','6','34','3','11'] , '-')
输出结果:
1-2-3-6-34-3-11
SELECT hasAny( [1,2,3,6,34,3,11] , [3,1])
输出结果:1
SELECT arrayDistinct([1,2,3,6,34,3,11])
输出结果:[1,2,3,6,34,11]

parseDateTimeBestEffort(toString(20191201000407)) as wet
输出结果:2019-12-01 00:04:07
上一篇下一篇

猜你喜欢

热点阅读