有关背包问题的棘手的mysql查询

Let's say that we have a user request. That request contains a decimal number. That decimal number is correlated with a table in the database, it is lower than the summary of all values of the fields in a proper column. But the request is not the exact summary of any possible values from that column.

On the other hand - it is not possible to increase that value, but it is possible to reduce any value of the field in this column, so some possible number of values will create a sum, that will match the user's request.

That is the problem, and I don't understand how to solve it. Maybe someone ever has done something similar, and can help me find a way out?

I am not really hoping for this, and I understand that it is a complicated thing even to explain, but I would much appreciate the solution.

$wa = 0.001;
$address = $address;
function recursion($wa)
{
  $resulte = db_select ('Credit_user','c')
  ->fields ('c')
  ->range(0,1)
  ->orderby('cr_ts', 'ASC')
->condition('c.affected','0','=')
->condition('c.amount','0','!=')
 ->execute();
foreach($resulte as $item) {
  global $code = $item->redeem_code;
  global $amounte = $item->amount; 
global $wai = $wa - $amounte;
if ($wai < 0){  
  "production code that should operate with different variations of $amounte and $redeem on last iteration"
  return;
}
elseif ($wai >= 0){  "production code that should operate with different variations of $amounte and $redeem on each iteration"

  return;

} else {
  function recursion($wa - $amounte);
}
}

}