我的表格中有三列:
Amount
,OrderNumber
,Customerid
对于每个customerid
,将分别有ordernumber
和amount
。
现在,我需要显示customerid
,Ordernumber
和Amount
(每个客户id的总金额)。
custid srcnumber amount
112 4344 20
112 7678 10
112 8766 30
34 6577 15
34 4566 5
预期:
custid srcnumber amount
112 4344 60
112 7678 60
112 8766 60
34 6577 20
34 4566 20
答案 0 :(得分:2)
使用sum() over (partition by ..)
分析函数来总结每行的数量:
select Customerid as custid,
OrderNumber as srcnumber,
sum(amount) over ( partition by Customerid ) as amount
from tab
order by custid desc