如何计算 Teradata SQL 中每组的平均值?

How to calculate mean value per group in Teradata SQL?

在 Teradata SQL 中有 table,如下所示:

SMS_ID | PRODUCT 
-------------------
11     | A
22     | A
33     | A
87     | B
89     | B
14     | C

我的问题是:如何在 Teradata 中计算 SQL 每个产品的 SMS 平均数? 因此,我需要如下内容:

AVG  | PRODUCT
-------
0.5  | A   -> because 3 / 6 = 0.5
0.33 | B   -> because 2 / 6 = 033
0.16 | C   -> because 1 / 6 = 0.16

您需要总数的分数:

SELECT
    product
   ,COUNT(*)  -- count per product
      / CAST(SUM(COUNT(*)) OVER () AS FLOAT) -- total count = sum of counts per procuct
FROM yourTable
GROUP BY PRODUCT