在oracle中对列进行分组
Grouping a column in oracle
我的 table 中有三列:
Amount
、OrderNumber
、Customerid
每个 customerid
会有 ordernumber
和 amount
。
现在我需要显示 customerid
、Ordernumber
和 Amount
(total 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
我的 table 中有三列:
Amount
、OrderNumber
、Customerid
每个 customerid
会有 ordernumber
和 amount
。
现在我需要显示 customerid
、Ordernumber
和 Amount
(total 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