Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

stored procedures - SQL : split a single row into multiple rows using capacity

I have a few items order by on the delivery date, I have the following items.

Item    Qty    Delivery date,
C       400    02/03/2021
B       200    02/14/2021
A       350    02/16/2021
D       300    02/19/2021

I can only do about 150 items a day (Capacity). My plan start date is 01/20/2021 ,Sunday is not plan and cannot exceed the Delivery date, I’ll need result like this:

Item    Qty    Delivery date    Plan Date
C       150    02/03/2021       01/20/2021
C       150    02/03/2021       01/21/2021
C       100    02/03/2021       01/22/2021
B       50     02/14/2021       01/22/2021
B       150    02/14/2021       01/23/2021
A       150    02/16/2021       01/25/2021
A       150    02/16/2021       01/26/2021
A       50     02/16/2021       01/27/2021
D       100    02/19/2021       01/27/2021
D       150    02/19/2021       01/28/2021
D       50     02/19/2021       01/29/2021

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you try using cursor for this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...