ウィンドウ関数で累積乗算(クエリの下)を実行することは可能ですか?
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