J
J
JuniorDeveloper2015-08-11 09:38:50
MySQL
JuniorDeveloper, 2015-08-11 09:38:50

ORDER BY on the result of dividing numbers from two fields of another table, how?

Hello, I need to sort in the ride table by the result of dividing the values ​​from two columns in the user table.
There are 2 tables:
ce5a58384798495a89ca193693182175.png
Ride model is connecting

public function getRideCustomer()
    {
        return $this->hasOne(User::className(), ['user_id' => 'ride_customer_id']);
    }

Used by yii2. It is necessary in the indexAction (list) at the time of setting $searchModel and $dataProvider or in the search() function located in RideSearch() - to sort rides by customer rating, i.e. rating = user_rating_sum / user_rating_count;.
How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NetyNicka, 2015-08-12
@JuniorDeveloper

RideSearch->search()

$query->orderBy('(user_rating_sum/user_rating_count) DESC');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question