在 sql 中存储项目分布

问题描述

请帮忙解决sql中的以下问题:

有 2 个表:

  • 板条箱 - 包含板条箱中当前项目的数量
  • Stores_demand - 包含每家商店所需的每件商品的数量
create table stores_demand
(sku    varchar(15),store1  int,store2  int,store3  int,store4  int,store5  int,store6  int,store7  int,store8  int,store9  int,store10 int,demand int);


INSERT INTO stores_demand
values
('A100000219003',20,15,135),('A500000001928',16,96),('A500000003308',200),('A500000006249',10,12,8,88),('A500000007035',7,75),('A500000007704',95),('A500000008759',5,93),('A500000008849',90),('A500000009363',2,137),('A500000010308',('A500000010309',('A500000011062',11,91),('A500000011362',('A500000011993',('A500000012153',('A500000014325',('A500000014701',110),('A500000014702',3,23);


create table crates  
(sku    varchar(15),crate_id varchar(30),total_quantity int);


INSERT INTO crates
values
('A100000219003','SH20000217-75',40),('A100000219003','SH20000217-78','SH20000217-79','SH20000217-83','SH20000217-84',42),'SH20000217-85','SH20000217-88',43),'SH20000218-88','SH20000267-57',45),'35WR21010117',32),'SH20000141-16',64),'SH20000234-159',30),'SH20000234-160','SH20000234-161','SH20000234-162','SH20000234-163','SH20000234-164','SH20000234-165','SH20000234-166','SH20000234-167','SH20000234-168','SH20000234-169','SH20000234-170','SH20000234-172',29),'102WR20019824',50),'99WR20019824','72WR20019824','15WR21000780',130),'107WR21007704','SH21000047-87',53),'201WR21001888',20),'202WR21001888','203WR21001888','204WR21001888',10),'63WR21011733','SH20000141-14',80),'SH20000141-15',37),'64WR21010979',220),'35WR21010979','50WR21008778',5),'52WR21008778',25),'6WR21014685',8),'SH20000141-24','138WR21010218',100),'19WR21014310','70WR20019824',250),'30WR21000780',140),'31WR21000780','126WR21008778','28WR21010117',24),'31WR21010117',23);

需要创建一个表格,将商店的数量除以板条箱大小和需求限制,并返回每个商店的数量和需要使用的板条箱数量(打开板条箱的剩余物将用作额外的,无需打开如果数量满足所有商店的要求,则下一个板条箱)。 例子: 需求:200 店铺数量:10 每店需求:20 型号:A12345

division/packing example

如上所示,每个商店需要 20 个单位,有 10 个商店,每个 sku A12345 的需求为 200,每个 crate 中装有不同的数量,如果需要从仓库中取出,“get_crate”列返回 crate 编号。如果不是,则返回 NULL。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)