select st,avg(vol)vol from tb where date between convert(varchar(10),dateadd(day,-3,getdate()),23) and convert(varchar(10),getdate(),23) group by st
to hjywyj 对时间间隔大的的种类这样算出的平均不对
select st,cast(avg(vol*1.0) as decimal(28,2))vol from tb a where exists (select 1 from (select top 4 b.date from tb b where a.st=b.st order by b.date desc)t where t.date=a.date) group by a.st
select st,avg(vol) as avg_vol from table where datediff('d',date,getdate())<=4 group by st
to hjywyj 试了,运行没问题,把分给你 to dong_y888 有的种类时间间隔大就不行 结贴,谢谢大家
对时间间隔大的的种类这样算出的平均不对
where exists (select 1 from (select top 4 b.date from tb b where a.st=b.st order by b.date desc)t where t.date=a.date)
group by a.st
where datediff('d',date,getdate())<=4
group by st
试了,运行没问题,把分给你
to dong_y888
有的种类时间间隔大就不行
结贴,谢谢大家