实时聚合投影支持的函数

Vertica 可以在以下聚合函数的实时聚合投影中聚合结果:

带 DISTINCT 的聚合函数

实时聚合投影可以支持包含用关键字 DISTINCT 限定的聚合函数的查询。需要满足以下要求:

  • 聚合表达式的求值结果必须为非常数。

  • 投影的 GROUP BY 子句必须指定聚合表达式。

例如,以下查询使用了 SUM(DISTINCT) 来计算给定区域的所有唯一薪金的总额:

SELECT customer_region, SUM(DISTINCT annual_income)::INT
   FROM customer_dimension GROUP BY customer_region;

此查询可以使用以下实时聚合投影,而该投影在其 GROUP BY 子句中指定了聚合列 (annual_income):

CREATE PROJECTION public.TotalRegionalIncome
(
 customer_region,
 annual_income,
 Count
)
AS
 SELECT customer_dimension.customer_region,
        customer_dimension.annual_income,
        count(*) AS Count
 FROM public.customer_dimension
 GROUP BY customer_dimension.customer_region,
          customer_dimension.annual_income
;