clickhouse窗口函数原创
ClickHouse窗口函数在数据分析及开发中应用十分广泛。
具体可在官网查看,这里列举部分常用函数进行示例学习。
- clickhouse 默认不允许使用窗口函数,可以在SQL末尾加:settings allow_experimental_window_functions = 1
SELECT
t1
, row_number() OVER (ORDER BY t1 ) AS s1
, rank() OVER (ORDER BY t1 ) AS s2
, dense_rank() OVER (ORDER BY t1 ) AS s3
from
(
select arrayJoin([1,2,3,2,4]) as t1
)
settings allow_experimental_window_functions = 1;
-- ┌─t1─┬─s1─┬─s2─┬─s3─┐
-- │ 1 │ 1 │ 1 │ 1 │
-- │ 2 │ 2 │ 2 │ 2 │
-- │ 2 │ 3 │ 2 │ 2 │
-- │ 3 │ 4 │ 4 │ 3 │
-- │ 4 │ 5 │ 5 │ 4 │
-- └────┴────┴────┴────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
- 02
- 2025-03-28拍婚纱照 原创04-02
- 03
- 2024-04-05的晚上 原创04-01