嗨,我正在尝试找到一种简单的方法来扩展数据库查询并按月份对记录进行分组(理想情况下,我希望下个月存储在“下一页”中)。有办法吗?
当前查询
@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location)
谢谢
答案 0 :(得分:0)
首先从日期字段中get month name开始,然后使用group
方法按月分组
@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location).group('strftime('%m', your_date_field)')
就您而言,我建议也按年份分组。在这种情况下,请使用以下代码:
@submissions = Submission.where(:Desired_Location => current_agent.Company_Business_Location).group('strftime('%Y %m', your_date_field)')