17,140
社区成员




with tab1 as (
select 1 ord, 3 qty, 'ce1' stype from dual union all
select 2 ord, 2 qty, 'ce1' from dual union all
select 3 ord, 4 qty, 'ce1' from dual
)
select t1.*,
sum(-t1.qty) over(partition by t1.stype order by t1.ord) + 5 nd
from tab1 t1;
我记得sqlserver里有分析函数啊,怎么搞这么麻烦?