【Hive】总体标准差stddev()

stddev()

计算基于给定的样本总体的标准偏差,为聚合函数,可使用窗口函数的表现方式。

-- 1.聚合函数
select col, stddev(num) as stddev_col
from (
    select 'A' as col, '1' as num
    union all
    select 'A' as col, '2' as num
    union all
    select 'A' as col, '3' as num
    union all
    select 'B' as col, '1' as num
    union all
    select 'B' as col, '2' as num
) as a
group by col
-- 2.窗口函数
select col, stddev(num) over(partition by col) as stddev_col
from (
    select 'A' as col, '1' as num
    union all
    select 'A' as col, '2' as num
    union all
    select 'A' as col, '3' as num
    union all
    select 'B' as col, '1' as num
    union all
    select 'B' as col, '2' as num
) as a

result1 【Hive】总体标准差stddev()_第1张图片 result2

你可能感兴趣的:(hive)