Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
648 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 Reply

0 votes
by (71.8m points)

I think you try using cursor for this case.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...