Home > database >  Help: SQL according to the customer order to delivery date, combined with the existing inventory, pu
Help: SQL according to the customer order to delivery date, combined with the existing inventory, pu

Time:11-22

Table 1: order demand form
Item number model did not pay the amount to the delivery date
001 A 1 20200101
002 A 2 20200102
003 B 20200101
004 B 20200102

table 2: the existing inventory list
Model inventory quantity
A 1
2 B

table 3: purchase not in list
Model did not pay the amount to the delivery date
A 1 20200110
A 2 20200112
B 2 20200110
B 2 20200112

table a demand according to the model, should be ordered by date of delivery;
First match table 2 have inventory, no inventory to match the table of three procurement;

for requirements, such as spot cannot satisfy the hope split into multiple lines,

hope the result is:
Item number model did not pay the amount to the delivery date can meet the number of spot/futures can delivery date
001 A, 20200101 1 spot 20200101
002 A, 20200102 1 20200110 futures
002 A, 20200102 1 20200112 futures
003 B 20200101 1 spot 20200101
003 B 20200101 2 futures 20200110
004 B 20200102 2 futures 20200112
004 B 2, 20200102 is not available

Dear god, please help the younger brother! Be very grateful! All the points given!
Thank you thank you thank you thank you!!!
The younger brother new SQL is non-negotiable,
Who is a great god can I get direct messages, there will be ChongXie!
  • Related