Hoge.group(:foo).sum(:bar)
# { foo => (barの合計) } という形のhashが返る
Hoge.group(:foo).select("foo, sum(bar)")
# Hogeクラスが返る
上だとHashなのでlimitやorderが使えないが下だとlimitやorderが使える
More than 5 years have passed since last update.
Hoge.group(:foo).sum(:bar)
# { foo => (barの合計) } という形のhashが返る
Hoge.group(:foo).select("foo, sum(bar)")
# Hogeクラスが返る
上だとHashなのでlimitやorderが使えないが下だとlimitやorderが使える
Register as a new user and use Qiita more conveniently