catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.84k stars 1.15k forks source link

multiply by where order #766

Closed MrMarci666 closed 6 years ago

MrMarci666 commented 6 years ago

Hi guys, I want to get an array from Offers from my db. i have "price" and "profit" field. I can order by profit OR price, but i want to order by "profit * price".

Here is my code:

    $containers = $database->select(TABLE_OFFERS, "*", [
       "AND" => ["cid" => $database->select(TABLE_PARTNERS, "cid", ['OR'=>['zip'=>$_SESSION['container']['googlePlace3_postal_code'],'city'=>$_SESSION['container']['googlePlace3_locality']]]), "mid" => (int)$material['id']],
       "GROUP" => 'size',
       "ORDER" => ['price'=>'ASC']
    ]);

"ORDER" => ["price * profit" => "ASC"]

doesn't work. :)

Please help me.

Thank you

catfan commented 6 years ago

I'm not sure multiply two columns will work on SQL or other database, but you can use Medoo::raw object for this case.

"ORDER" => Medoo::raw("<price> * <profit> ASC")