How would I convert the below list into multiple rows based on the qty but grouped by the item?
Current results.
ITEM QTY
----- ----
12345 1
12346 2
12347 3
This is the desired results
ITEM QTY
----- ----
12345 1
12346 1
12346 1
12347 1
12347 1
12347 1
This is the query
SELECT a.item,sum(b.qty) as qty
FROM table1 a, table2 b
WHERE a.item_id = b.item_id
group by a.item
order by a.item_id
You can do this by applying the
rownumto the records:see SQL Fiddle with Demo