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

When I tried on mysql
select max(peak_kw) peak,month from sola_daylies group by month;
It returns as I expected

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.connection.execute

results = ActiveRecord::Base.connection.execute(“select max(peak_kw) peak,month from sola_daylies group by month”)

pp results[0]

``

Thank you, I got it.

2015年1月20日火曜日 5時55分31秒 UTC+9 Daniel Loureiro: