AVG功能返回错误的结果

时间:2017-06-14 17:31:41

标签: sql oracle function

我想从我的数据集中的一列获得平均值。但是,当我在excel上测试时,sql结果返回错误的结果。

表格结构如下:

 ticker_symb   day_sum_eff_dt  cusip     clos_prc  n_clos_prc  DIFF   AVRG
 ASLR           05/17        13799F229     0.234    0.234        0     0

到目前为止,这是我的代码:

SELECT 
ticker_symb, day_sum_eff_dt, cusip, 
clos_prc, 
n_clos_prc,
      case
       when  clos_prc is null and n_clos_prc is not null 
       then (n_clos_prc - LAG( n_clos_prc ignore nulls) OVER (ORDER BY cusip)) 
       else NULL
       end DIFF,
AVG(DIFF) OVER(PARTITION BY cusip ) AS avrg
FROM (SELECT  
day_sum_eff_dt, cusip,
ticker_symb_cd, 
clos_prc, 
navgen_clos_prc
  case
       when  clos_prc is null and n_clos_prc is not null 
       then (n_clos_prc - LAG( n_clos_prc ignore nulls) OVER (ORDER BY cusip)) 
       else NULL
       end DIFF
        from DAILY_SUMMARY
where
day_sum_eff_dt > sysdate-60
and  (cusip in ( '13799F229'))
order by  cusip, day_sum_eff_dt;

DIFF列的平均结果是 -0.00057993076923076

但是实际平均值是 -0.0002949250000 。并不是说你得到的结果是相同的,但这会让你知道结果的差异

代码可能出现什么问题?

0 个答案:

没有答案