啥数据库啊,可以先在数据库拆开来吧
with a as(
select 'A' AS A,3 AS B,1 min_qty,6 as qty
UNION ALL
select 'A' AS A,2 AS B,1,7 as qty
)
select a.a,MIN_QTY,SEQ,a.b
,case when MIN_QTY * rnk < b THEN MIN_QTY ELSE b-MIN_QTY*(rnk-1) END AS NEW_QTY,qty
from (
select a.a,a.b,MIN_QTY,count(MIN_QTY) over ( partition by a ) as SEQ,b.number + 1 as rnk,qty
from a
CROSS join master..spt_values b
where b.number * a.MIN_QTY <a.B and b.Type = 'P'
) a