1.情景描述:
(1) 假设有这样一张表:
create table test1(id1 number,id2 number,id3 number)
(2)模拟数据如下:
1  1  1
2  2  1
3  3  2
4  4  2
(3)我的SQL如下:
select id1,id2,stddev(id2) over(partition by id3) as sd from test1
(4)输出结果如下:
id1     id2     sd
=================================
1 1 0.707106781186548
2 2 0.707106781186548
3 3 0.707106781186548
4 4 0.707106781186548
(5)问题
我用stddev函数计算出这个标准差值,但是客户要求不用这个标准差公式进行计算,他们给了一个”类标准差“计算公式,而我原来的代码逻辑直接用了这个Oralce计算出来的标准差值进行了处理,如果要改代码逻辑,感觉改动很大,现在我想按照客户的计算公式,自己写个”类标准差“计算函数,这样我的代码逻辑就可以不用改了,直接调用我自己的函数就可以解决问题,有没有哪位大侠愿意提供点思路,怎样写这个函数?非常感谢!(分不够,等会再加)

解决方案 »

  1.   

    原标准差公式:
    a1,...,an ,平均值:m
    ((a1-m)2(平方)+...+(an-m)2(平方))/n-1  然后再开平方.
    现在客户的公式是:
    (|a1-m|+...+|an-m|)/n
    貌似没法组合!
      

  2.   

    推荐你看 matlab去吧
    那里面估计有
      

  3.   

    大家都忙乎着过年了,也没人来帮忙回答了!我自己找了个比较绰的方法!select id1,id2,id3,s/count(id3) over(partition by id3) from(
    select id1,id2,id3,sum(a)  over(partition by id3) s from(
    select id1,id2,id3,abs(id2-a1) a from(
    select id1,id2,id3,avg(id2) over(partition by id3) a1 from test1)))