[Rails] Re: How can I? such as "select max(peak_kw) peak,month from sola_daylies group by month;"

2015-01-20 Thread Winterboum
Thank you, I got it. 2015年1月20日火曜日 5時55分31秒 UTC+9 Daniel Loureiro: > > Try this: > > Sola::Dayly.group(:month).maximum(:peak_kw) > > > *Explanation:* > "find_by_sql" is to be used to get real records, not database > calculations. The "Group", "Max" and other statements produce calculations, >

[Rails] Re: How can I? such as "select max(peak_kw) peak,month from sola_daylies group by month;"

2015-01-19 Thread Daniel Loureiro
Try this: Sola::Dayly.group(:month).maximum(:peak_kw) *Explanation:* "find_by_sql" is to be used to get real records, not database calculations. The "Group", "Max" and other statements produce calculations, not real records. If you want to do a *raw SQL*, do with " *ActiveRecord::Base.connect