Answer the question
In order to leave comments, you need to log in
How to sort by simple and complex parameter in mysql?
Good afternoon,
There are 3 tables: Users, Offers, Ratings. It is necessary that at first there was a sorting by ratings in descending order, then by the offered prices from the offer in ascending order. To have higher priority offers first:
Users:
--------------------
m_users
--------------------
id
name
--------------------
Offers:
--------------------
mс_offers
----- ---------------
id
user_id
price
--------------------
Ratings:
---------- ----------
ms_offers
--------------------
id
user_id
rate
---------------- ----
Approximately threw nonsense:
SELECT * FROM (SELECT * FROM m_users LEFT JOIN mc_rating ON m_users .id = mc_rating.user_id ORDER BY ( SUM(rate) / COUNT(rate) GROUP BY mc_rating.user_id ) as users LEFT JOIN mc_offersON users.id = mc_offers.user_id ORDER BY mc_offers.price
Answer the question
In order to leave comments, you need to log in
SELECT * FROM m_users
LEFT JOIN mc_rating ON m_users .id = mc_rating.user_id
LEFT JOIN mc_offers ON users.id = mc_offers.user_id
ORDER BY ( SUM(rate) / COUNT(rate) GROUP BY mc_rating.user_id ) DESC, mc_offers.price
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question