I am sorry for re-uploading this quesiton, but I really want the answer.
Kindly allow me to ask this question again and hope your kind support.
The question is to find the right size box which allow the logistic business to save the money when shipping.
We have 2 tables which are boxes and products.
Boxes table contains each ID and dimensions per box. 'w' for wide, 'd' for depth and 'h' for height. Please assume we have just 3 box samples for our convenience.
Products table includes also product ID, dimensions. Dimensions has the same meaning as boxes table. 'layable' means the product can be packaged not only straight position but also layable position. For instance product 'g' is a fragile bottle not being able to put horizontal position in the box. Thus this is 'n' in layable column.
This question needs to query each product ID with the right size box. The right size box means the product needs to be shipped with box that is the least space.
Hope your kind help. Thanks.
boxes:
BOX_SIZE | W | D | H |
---|---|---|---|
S | 353 | 250 | 25 |
M | 450 | 350 | 160 |
L | 610 | 460 | 460 |
products:
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 |
Expected output:
ID | BOX_SIZE |
---|---|
a | S |
b | M |
... | .... |
... | .... |
... | .... |
g | S |
h | M |
i | L |
j | not available |
Statements to create and populate the tables for testing:
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;