开发者

Using DISTINCT with ActiveRecord

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜