单个 DISTINCT 聚合

计算 DISTINCT 聚合时,Vertica 首先会删除聚合参数中的所有重复值,从而找到非重复值。然后,它会计算聚合。

例如,您可以将以下查询:

SELECT a, b, COUNT(DISTINCT c) AS dcnt FROM table1 GROUP BY a, b;

重写为:

SELECT a, b, COUNT(dcnt) FROM
  (SELECT a, b, c AS dcnt FROM table1 GROUP BY a, b, c)
GROUP BY a, b;

为了最大限度提高执行速度,请为 GROUP BY 查询应用优化技术。