Ruby Rails Complex SQL with aggregate function and DayOfWeek
问题 Rails 2.3.4 I have searched google, and have not found an answer to my dilemma. For this discussion, I have two models. Users and Entries. Users can have many Entries (one for each day). Entries have values and sent_at dates. I want to query and display the average value of entries for a user BY DAY OF WEEK. So if a user has entered values for, say, the past 3 weeks, I want to show the average value for Sundays, Mondays, etc. In MySQL, it is simple: SELECT DAYOFWEEK(sent_at) as day, AVG(value