how would one go about finding solutions to all possible combinations of a,b,c,d,e,f where
a+b+c+d+e+f = x
given a,b,c,d,e,f are integers between 0-999 and x is a fixed integer
and the solution
a,b,c,d,e,f < y
(where each comma is a thousand separator)
ex. the huge number 304,153,525,784,175,764 is a solution to x=2705
since: 304+153+525+784+175+764 = 2705
here's a query i am trying for x=2705 and y=304153525784175764
SELECT
a.id,
b.id,
c.id,
d.id,
e.id,
f.id,
a.id+b.id+c.id+d.id+e.id+f.id AS sum
a.id*1000*1000*1000*1000*1000+
b.id*1000*1000*1000*1000+
c.id*1000*1000*1000+
d.id*1000*1000+
e.id*1000+
f.id AS solution
FROM a JOIN b JOIN c JOIN d JOIN e JOIN f
WHERE sum = 2705
AND solution <= 304153525784175764
ORDER BY solution DESC
how can one simplify this query which is currently far too big
is there perhaps a simpler way to get the solutions?