I'm using ActiveRecord / RoR开发者_开发问答.
My table looks like this:
id (int), start_time(time), end_time(time), ...
1, 20:00, 23:00
2, 20:00, 23:00
3, 16:00, 20:00
4, 16:00, 23:00
5, 20:00, 22:00
6, 16:00, 20:00
I need to return the records that have a combination distinct start_time
+ end_time
combination.
YourModelClass.select("DISTINCT start_time, end_time")
This will return objects that aren't strictly records but they will inherit from ActiveRecord::Base and you can do pretty much anything with those objects that doesn't write to the database.
http://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields
精彩评论