Sum a column of a table based on another sum of a table

前端 未结 1 1212
不思量自难忘°
不思量自难忘° 2021-01-21 08:18

I have this code:

declare @ReportLines table 
    (RebateInvoiceID int, 
     RebateSetupID int ,
     ShortItemNo float primary key(RebateInvoiceID,RebateSetupI         


        
相关标签:
1条回答
  • 2021-01-21 09:06

    You can make another Nesty query... Something Like this:

    insert @ReportLines
    select
       RebateInvoiceID
       , ID
       , ShortItemNo
       , TotalAmount
       , sum(round(TotalAmount,2)) as InvoiceTotal
       , TotalQuantity
    from
    ( 
       select
       i.RebateInvoiceID
       , coalesce(rs.WholesalerRebateSetupID,r.RebateSetupID) as ID
       , bl.ShortItemNo
       , sum(round(r.Amount,2)) as TotalAmount
       , sum(r.Quantity) TotalQuantity
      from (... <the rest of your code here> ...) 
    ) As MyTable
    group by
     RebateInvoiceID, ID, ShortItemNo, TotalAmount, TotalQuantity
    
    0 讨论(0)
提交回复
热议问题