Answer the question
In order to leave comments, you need to log in
How to display the minimum price in a group?
I read here rusrails.ru/active-record-query-interface 7th point, but I didn’t understand something ....
There is a Room model. They have a plan_id parameter. You need to group them by plan_id and display the cheapest one from the group.
Right now I'm doing this: Room.order(price: :asc).group("plan_id"). If you put desc, then it displays the most expensive one, and if asc, then the logic is not clear at all. As I understand it, somewhere you need to specify min (price) somewhere, but I don’t understand where and how.
Help, people! Thanks in advance)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question