再帰CTEを有するアプローチ。
with recursive cte(orderid,item,qty,val) as
(select orderid, item, qty, 1
from t --this is your tablename
union all
select c.orderid, c.item, c.qty-1, c.val
from t
join cte c on t.orderid=c.orderid and t.item=c.item and c.qty>1
)
select orderid,item,val as qty
from cte
order by 1,2
や数字テーブルを持つ(=あなたが持つことができる最大量を、すべての数字を生成する)
with recursive cte(num) as (select 1 num
union all
select num+1 from cte where num < 1000 --change this to max quantity
)
select orderid, item, 1 as qty
from t
join cte c on t.qty >= c.num
order by 1,2