I have four fields a, b, price and sum. I need to automatically fill in the sum, but so that the price multiplied by the smaller of the fields. How to make such a condition? Thank!

  • one
    You put php and mysql tags - your question is about how to do this in php or how to do it in a SQL query mysql? MySQL has the least() function, for example - Mike
  • Yes, another mysql option is of interest. That is, it will look like this: UPDATE goods SET sum = price * least (a, b); ? - user3416803

2 answers 2

 UPDATE `table` SET `sum` = `price` * LEAST(`a`, `b`); 

    To find the lowest value, the min function will help you. Http://php.net/manual/ru/function.min.php

     $sum = $price*min($a,$b);