问题
i have a question about sql query. i want to duplicate a one row with same value, The number of lines must be same with the value of quantity
example i have 1 data like this
Item ItemName Quantity
B100 Mouse 10
but i want to be like this
Item ItemName Quantity
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
B100 Mouse 10
can you help me
Thanks Before
回答1:
Create a numbers
table and just do a CROSS JOIN
with it
select Item , ItemName , Quantity
from yourtable A
cross join (select num from numbers) b
where a.Quantity <= b.num
To generate sequential numbers in Mysql
check the below answers
- generate an integer sequence in MySQL
- Generating a range of numbers in MySQL
来源:https://stackoverflow.com/questions/34253461/repeat-a-result-row-multiple-times-by-value-in-row