× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Rob,

Thanks for this. I adapted this using our actual tables... Assuming I did it correctly (big assumption) the result set contains boxes that contain one of the items/qty.

I might be going down the wrong path here anyway.

What I'm really trying to do is this:

Given an order containing
1 of widget1
1 of widget2
2 of widget3

Knowing the dimensions of each item, I would like to determine what shipping carton to use.
I was hoping I could my historical data to extrapolate the answer... but that may be the wrong approach.

Would be nice to call some software that would do that for you.

Thx,
Greg

-----Original Message-----
From: MIDRANGE-L <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Rob Berendt
Sent: Monday, August 29, 2022 9:52 AM
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxxxxxxxx>
Subject: RE: SQL Question

Sort of like this?
create table rob.cartonarrangement (
cartonarrangementid integer,
carton varchar(30),
itemnumber varchar(30),
cartonquantity integer
);
drop table rob.cartonarrangement;
insert into rob.cartonarrangement values(1, 'boxA', 'widget1', 3);
insert into rob.cartonarrangement values(1, 'boxA', 'widget2', 1);
insert into rob.cartonarrangement values(1, 'boxA', 'widget3', 1);
insert into rob.cartonarrangement values(2, 'boxB', 'widget2', 1);
insert into rob.cartonarrangement values(2, 'boxB', 'widget3', 1);
create table rob.selection (
itemnumber varchar(30),
cartonquantity integer
);
insert into rob.selection values('widget2', 1);
insert into rob.selection values('widget3', 1);

set schema = 'ROB';

With t1 as (
select cartonarrangementid, count(*) as rowcount
from cartonarrangement
group by cartonarrangementid)
select * from t1;

With t1 as (
select cartonarrangementid, count(*) as rowcount
from cartonarrangement
group by cartonarrangementid),
T2 as (
select count(*) as rowcount
from selection),
T3 as (
select *
from cartonarrangement
where itemnumber concat char(cartonquantity) in (
select itemnumber concat char(cartonquantity) from selection))

select t3.*, b.rowcount, c.rowcount
from t3,
lateral (select t1.rowcount from t1
where t1.cartonarrangementid = t3.cartonarrangementid) b,
lateral (select t2.rowcount from t2) c
where b.rowcount = c.rowcount
;

Rob Berendt

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.