将值与总体平均值进行比较

时间:2014-03-26 17:05:34

标签: sql-server-2008

我想将ticker=7203 JT Equity的每个EPSF1值除以EPSF1行的平均66,000值,我不知道如何合并这两个查询

select Date, Ticker,EPSF1 
from tblForecasts 
where EPSF1 is not null 
and Ticker='7203 jt equity'

select AVG(epsf1)

1 个答案:

答案 0 :(得分:0)

声明变量,将平均值存储在那里,然后在查询中使用它:

declare @avg decimal
select @avg = AVG(epsf1) from tblForecasts 

select Date, Ticker,EPSF1 / @avg
from tblForecasts 
where EPSF1 is not null 
and Ticker='7203 jt equity'