The Table I have:
+--------+--------------------+
|item_id| value |
+--------+--------------------+
| 1 | 1 |
| 2 | 4 |
| 3 | 2 |
| 4 | 6 |
+--------+--------------------+
What the SQL Query Result should be: A random combination of items that sum up to 10 with a variable number of different items (in this case 2.)
+--------------+--------------------+-------------+
|item_id | amount | sum |
+--------------+--------------------+-------------+
|2 |2 |8 |
|3 |1 |2 |
+--------------+--------------------+-------------+
The results show
You get 2 times item 2 (which has the value of 4 so it adds to a sum of 8).
And you get one time item 3 (which has the value of 2)
This combination sums up to 10.
Is that even possible, when it should not be the same combination always and picked random if there are other possibilitys?