很抱歉重新上传这个问题,但我真的想要答案。
请允许我再次问这个问题并希望您的支持。
问题是找到合适尺寸的盒子,让物流企业在运输时节省资金。
我们有两张桌子,分别是盒子和产品。
盒子表包含每个盒子的 ID 和尺寸。
“w”代表宽度,“d”代表深度,“h”代表高度。为了方便起见,请假设我们只有 3 盒样品。
产品表还包括产品 ID、尺寸。维度与盒子表的含义相同。
“可平放”是指产品不仅可以平放包装,还可以平放包装。例如,产品“g”是易碎瓶子,无法水平放置在盒子中。因此,这是可放置列中的“n”。
本题需要查询每个产品ID的大小合适的框。
合适尺寸的盒子意味着产品需要使用空间最小的盒子来运输。
希望您的好心帮助。谢谢。
boxes:
BOX_SIZE |
W |
D |
H |
S |
353 |
250 |
25 |
M |
450 |
350 |
160 |
L |
610 |
460 |
460 |
产品:
ID |
W |
D |
H |
LAYABLE |
a |
350 |
250 |
25 |
y |
b |
450 |
250 |
160 |
y |
c |
510 |
450 |
450 |
y |
d |
350 |
250 |
25 |
y |
e |
550 |
350 |
160 |
y |
f |
410 |
400 |
430 |
n |
g |
350 |
240 |
25 |
n |
h |
450 |
350 |
160 |
n |
i |
310 |
360 |
430 |
n |
j |
500 |
500 |
600 |
y |
预期输出:
ID |
BOX_SIZE |
a |
S |
b |
M |
... |
.... |
... |
.... |
... |
.... |
g |
S |
h |
M |
i |
L |
j |
not available |
创建和填充测试表的语句:
create table boxes
( box_size char(1) primary key
, w number not null
, d number not null
, h number not null
)
;
insert into boxes (box_size, w, d, h) values ('S', 353, 250, 25);
insert into boxes (box_size, w, d, h) values ('M', 450, 350, 160);
insert into boxes (box_size, w, d, h) values ('L', 610, 460, 460);
create table products
( id varchar2(10) primary key
, w number not null
, d number not null
, h number not null
, layable char(1) check(layable in ('y', 'n'))
)
;
insert into products (id, w, d, h, layable) values ('a', 350, 250, 25, 'y');
insert into products (id, w, d, h, layable) values ('b', 450, 250, 160, 'y');
insert into products (id, w, d, h, layable) values ('c', 510, 450, 450, 'y');
insert into products (id, w, d, h, layable) values ('d', 350, 250, 25, 'y');
insert into products (id, w, d, h, layable) values ('e', 550, 350, 160, 'y');
insert into products (id, w, d, h, layable) values ('f', 410, 400, 430, 'n');
insert into products (id, w, d, h, layable) values ('g', 350, 240, 25, 'n');
insert into products (id, w, d, h, layable) values ('h', 450, 350, 160, 'n');
insert into products (id, w, d, h, layable) values ('i', 310, 360, 430, 'n');
insert into products (id, w, d, h, layable) values ('j', 500, 500, 600, 'y');
commit;