在oracle中对列进行分组

时间:2019-07-14 11:10:24

标签: sql oracle

我的表格中有三列: AmountOrderNumberCustomerid

对于每个customerid,将分别有ordernumberamount。 现在,我需要显示customeridOrdernumberAmount每个客户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

1 个答案:

答案 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

Demo