获取oracle中每行的mean和stddev

时间:2015-08-31 06:35:40

标签: sql oracle oracle10g

我想在每一行中得到平均值以及标准偏差。这样我就可以找到哪些值来自stddev。下面的代码给了我stddev。

SELECT reccount, 
   STDDEV(reccount) OVER (ORDER BY reccount) "StdDev"
   from
(select 10 as reccount from dual union
select 15 as reccount from dual union
select 20 as reccount from dual union
select 16 as reccount from dual ) A;

如果使用平均功能,则不会出错。

每行可以返回avg / mean吗?

1 个答案:

答案 0 :(得分:1)

您可以使用以下查询

SELECT reccount, 
   STDDEV(reccount) OVER (ORDER BY reccount) "StdDev",avg(reccount) OVER ()
   from
(select 10 as reccount from dual union
select 15 as reccount from dual union
select 20 as reccount from dual union
select 16 as reccount from dual ) A;

DEMO HERE