如何显示仅高于或低于30天平均值10%的数据?

时间:2012-02-08 19:53:23

标签: sql between average


我正在寻找以下问题的解决方案:
我写了30天的文件来查看每天产生一次计数的文件。

SELECT reuseid, hexample, hTimeframe, irodger, dateandtime
From reusing.reuse
WHERE hexample= 'RDM Daddy'
      and hTimeframe= 'TSBC0002.dlt.*.dat'
      and ((GETDATE()-dateandtime) < 32.0)
      and irodger<>(SELECT AVG(irodger) FROM reusing.reuse)
ORDER by dateandtime desc

我需要采取过去30天的平均值。然后,如果当天的金额是+/- 10%( 1.1 / .9)......我需要产生错误......

此当前查询会生成过去30天内的数据,并向我显示当前平均值之上或之下的数据,但不会显示介于两者之间的数据。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

也许这种操作可以解决您的问题:

SELECT reuseid, hexample, hTimeframe, irodger, dateandtime
From reusing.reuse
WHERE hexample= 'RDM Daddy'
      and hTimeframe= 'TSBC0002.dlt.*.dat'
      and ((GETDATE()-dateandtime) < 32.0)
      -- Here :
      and (irodger/(SELECT AVG(irodger) FROM reusing.reuse)) NOT BETWEEN 0.9 AND 1.1
ORDER by dateandtime desc