跳到主要内容
跳到主要内容

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,而且这是从第 2 个区间开始的:

SELECT maxIntersectionsPosition(start, end) FROM my_events;

响应:

2

换句话说,(1,6) 这一行是 3 个相交区间的起点,而 3 是区间相交的最大个数。