我可以通过查询找到总数:
with sub_total as (
select
*,
sum( qty*price ) OVER( PARTITION BY invoice_id, group_id ) AS order_cost
from invoice
)
-- Here how I get is expected result:
select *,
(SELECT sum(x) from (SELECT sum( DISTINCT order_cost ) AS x FROM sub_total sub_i GROUP BY invoice_id, group_id) t) as total_cost
from sub_total;
是否可以通过窗口函数找到这四个数字中的sum
?
我想这应该可以,但不幸的是没有:
sum( DISTINCT order_cost ) OVER ( PARTITION BY invoice_id, group_id ORDER BY group_id RANGE unbound preceeding and unbound following )
这里是fiddle