有没有办法创建一个与数据库无关的查询:
group by DAYOFMONTH(performed_on)
我需要它至少在MySQL和Postgres中工作。我正在使用Rails / ActiveRecord所以也许有些东西可以提供帮助吗?这是我的代码:
@works = Work.where(:user_id => current_user.id, :performed_on => (@date.beginning_of_month..@date.end_of_month))
...
@works.select('sum(hours) as total_hours, DAYOFMONTH(performed_on) as day').group('DAYOFMONTH(performed_on)')