在oracle中对列进行分组

Grouping a column in oracle

我的 table 中有三列: AmountOrderNumberCustomerid

每个 customerid 会有 ordernumberamount。 现在我需要显示 customeridOrdernumberAmounttotal Amount- for each customerid)。

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

使用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