是否可以使用窗口函数进行累积乘法(如下查询)
select Id, Qty
into #temp
from(
select 1 Id, 5 Qty
union
select 2, 6
union
select 3, 3
)dvt
select
t1.Id
,exp(sum(log( t2.Qty))) CumulativeMultiply
from #temp t1
inner join #temp t2
on t2.Id <= t1.Id
group
by t1.Id
order
by t1.Id
喜欢:
select
t1.Id
,exp(sum(log( t2.Qty))) over (partition by t1.Id order by t1.Id rows between unbounded preceding and current row ) CumulativeMultiply
from #temp t1
inner join #temp t2
on t2.Id <= t1.Id
但得到错误:
函数“exp”不是有效的窗口函数,不能与 OVER 子句一起使用
更新: 实际上我想要的结果:
Id CumulativeMultiply
----------- ----------------------
1 5
2 30
3 90