示例:计算点击率(CTR)
CAST(SUM(num_clicks) as DOUBLE) / CAST(SUM(num_impression) as DOUBLE) as CTR
如何计算CTR的标准偏差? stddev(CTR)不会工作,因为它将是一个嵌套的混合函数...而且,我不能先计算CTR然后再运行stddev。
答案 0 :(得分:1)
您可以先计算点击率,然后使用子查询在其上运行STDDEV_POP
。
SELECT STDDEV_POP(ctr) AS ctr_stddev
FROM (
SELECT CAST(SUM(num_clicks) as DOUBLE) / CAST(SUM(num_impression) as DOUBLE) AS ctr
FROM yourTable
WHERE ...
GROUP BY ad_id) AS temp