如何将当前剩余库存列 负数值 生成序号
select *,
case when xh>=0 then null else ROW_NUMBER()over(order by xh ) end as xh
from (
select 5 as xh
union all
select 6 as xh
select -7 as xh
select -8 as xh
) t1
参考
啥意思
分两段查询,用UNION ALL 连接,然后库存小于0的那段排序,逻辑清晰简单