window 函数的累积乘法,'exp' 不是有效的 windowing 函数

Cumulative multiplication with window functions, 'exp' is not a valid windowing function

是否可以使用 window 函数进行累积乘法(低于查询)

    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

但出现错误:

The function 'exp' is not a valid windowing function, and cannot be used with the OVER clause

更新: 我真正想要的结果:

Id          CumulativeMultiply
----------- ----------------------
1           5
2           30
3           90

只有聚合函数是有效的窗口函数。

我没有测试代码,但你需要以某种方式将 2 分开:

SELECT Id, exp(cm) CumulativeMultiply
FROM (
select 
        Id
        ,sum(log(Qty)) over (partition by Id order by Id rows between unbounded preceding and current row )  cm
        from #temp
) d

Sum Over(Order by)不需要自连接来查找以前的记录并相乘

 select  
        Id
        ,exp(sum(log( Qty))
        over (order by Id )) CumulativeMultiply from #temp