Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想为特定客户创建一个包含所有订单号和发货的表格。有时一个订单上有多个发货,因此,为了包括所有发货和订单,会有不同发货的重复订单。有没有办法包含重复的订单号,但每个唯一订单的金额只显示一次?例如:
如果我理解正确,您可以使用窗口函数:
select t.*, (case when 1 = row_number() over (partition by order# order by shipment) then sum(amount) over (partition by order#) end) as order_amount from t order by order#, shipment;