絕不是最漂亮的東西;並假設數量將永遠不會超過10. 有更好的方法來做到這一點...但涉及PL \ SQL或T-SQL不能想到一個直接的SQL答案。
Insert into yourTablename
(
(Select supplier, Qty From YourTableName where Qty-1 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-2 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-3 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-4 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-5 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-6 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-7 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-8 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-9 > 0)
UNION
(Select supplier, Qty From YourTableName where Qty-10 > 0)
)
此外,這是一筆交易;如果這不是第一次;你必須清理數據然後重試。 (又不是我最喜歡的答案,但限制只SQL ...)
有沒有被允許或可能有任何數量的數量最多? – xQbert
+1對於有趣的問題 – whytheq
您是插入同一張表還是插入一張新表? – Bort