0
特定の列の平均値、最大値、最小値を返したいクエリがあります。しかし、私が2回以上実行すると、結果はお互いに異なります。つまり、同じデータセットでクエリを実行するたびに、平均結果が異なります。なぜAVG、MAX、MINが異なる結果を返すのですか?
なぜですか?
相続コード:
WITH avr AS (
SELECT
ticker_symb,
day_sum,
cusip,
clos_prc,
nclos_prc,
case
when clos_prc is null and nclos_prc is not null
then (nclos_prc - LAG(nclos_prc ignore nulls) OVER (Partition by cusip ORDER BY cusip asc))
when clos_prc is not null and nclos_prc is null
then LEAD(nclos_prc ignore nulls) OVER (Partition by cusip ORDER BY cusip asc)- LAG(naclos_prc ignore nulls) OVER (Partition by cusip ORDER BY cusip)
else NULL
end diff
from DAILY_SUMMARY
where (cusip in (select distinct cusip from thistory where
td between to_date('1-JAN-2017') and to_date('10-JUN-2017'))))
SELECT ticker_symb,
day_sum,
cusip,
clos_prc,
nclos_prc,
diff,
AVG(diff) OVER() as avr,
MAX(diff) OVER() as max_diff,
MIN(diff) OVER() as min_diff ,
FROM avr
where day_sum >'1-JAN-2017'
ORDER BY cusip;
多分私は誤解していますが、なぜ彼らは同じでしょうか?私はあなたがクエリを実行する時間の間に 'daily_summary'に新しいデータが書き込まれていると仮定します。 – SQLChao
同じデータセットがありません – ana
私はクエリーを連続して実行しています。したがって、データセットに違いはありません – ana