I have 36 data of box with weights:
24.8 24.7 24.6 24.6 24.65 24.75 25.1 24.7 24.7 24.9 24.8 24.65 24.85 24.85 24.7 24.75 25 24.6 24.55 24.6 24.5 24.55 24.5 24.85 24.7 24.65 24.4 24.4 24.55 24.45 24.35 24.95 24.65 24.85 24.75 25
Which combination of 12 boxes to get results of 296.35? Can I can provide this with stored procedure or cross join in MySQL?
The query to insert are:
insert tbl(weight) values(24.8);
insert tbl(weight) values(24.7);
insert tbl(weight) values(24.6);
insert tbl(weight) values(24.6);
insert tbl(weight) values(24.65);
insert tbl(weight) values(24.75);
insert tbl(weight) values(25.1);
insert tbl(weight) values(24.7);
insert tbl(weight) values(24.7);
insert tbl(weight) values(24.9);
insert tbl(weight) values(24.8);
insert tbl(weight) values(24.65);
insert tbl(weight) values(24.85);
insert tbl(weight) values(24.85);
insert tbl(weight) values(24.7);
insert tbl(weight) values(24.75);
insert tbl(weight) values(25);
insert tbl(weight) values(24.6);
insert tbl(weight) values(24.55);
insert tbl(weight) values(24.6);
insert tbl(weight) values(24.5);
insert tbl(weight) values(24.55);
insert tbl(weight) values(24.5);
insert tbl(weight) values(24.85);
insert tbl(weight) values(24.7);
insert tbl(weight) values(24.65);
insert tbl(weight) values(24.4);
insert tbl(weight) values(24.4);
insert tbl(weight) values(24.55);
insert tbl(weight) values(24.45);
insert tbl(weight) values(24.35);
insert tbl(weight) values(24.95);
insert tbl(weight) values(24.65);
insert tbl(weight) values(24.85);
insert tbl(weight) values(24.75);
insert tbl(weight) values(25);
Best Answer
Possible issues:
id
or something instead of weight for avoiding dups.Replace the WHERE clause with something like:
This would probably run a lot faster in any programming language then SQL.
I worry that this query will not complete in my lifetime. I think it would take billions, maybe trillions of iterations.
OR
The code above is "brute force". With some more thinking, it should be possible to 'prune' the list to cut back significantly (down from trillions to billions??) the amount of work. But that would need a recursive CTE (upgrade to MySQL 8.0) or, as I say, use a real programming language.