跳转到主要内容
跳转到主要内容
编辑此页

maxIntersectionsPosition

聚合函数,用于计算maxIntersections 函数的出现位置。

语法是

maxIntersectionsPosition(start_column, end_column)

参数

  • start_column – 数值列,表示每个区间的起始位置。如果 start_columnNULL 或 0,则会跳过该区间。

  • end_column - 数值列,表示每个区间的结束位置。如果 end_columnNULL 或 0,则会跳过该区间。

返回值

返回相交区间数量最多的起始位置。

示例

CREATE TABLE my_events (
start UInt32,
end UInt32
)
Engine = MergeTree
ORDER BY tuple();

INSERT INTO my_events VALUES
(1, 3),
(1, 6),
(2, 5),
(3, 7);

区间如下所示

1 - 3
1 - - - - 6
2 - - 5
3 - - - 7

请注意,其中三个区间都有共同的值 4,并且从第二个区间开始

SELECT maxIntersectionsPosition(start, end) FROM my_events;

响应

2

换句话说,(1,6) 行是 3 个相交区间的起始位置,而 3 是相交区间的最大数量。