绝不是最漂亮的东西;并假设 QTY 永远不会超过 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 ......)