Artificial intelligent assistant

rails テーブルのレコードをid毎合算して集計する→ランキングとして表示 rails (talent)(popularitys) select * from popularitys; id | user_id | talent_id | | 1 | 1 | 1 | | 2 | 3 | 1 | | 3 | 5 | 1 | | 4 | 2 | 2 | | 5 | 7 | 4 | | 6 | 9 | 2 | | 7 | 8 | 3 | | 8 | 6 | 4 | (popularitys)talent_idid(sum) 1 talent_id: 1 sum= 3 2 talent_id: 2 sum= 2 2 talent_id: 4 sum= 2 3 talent_id: 4 sum= 2 4 talent_id: 3 sum= 1 ※id Popularity.where(talent_id: 1).count => 3

Popularity.group(:talent_id).order('count_talent_id desc').count(:talent_id)


`talent_id``count`



* ActiveRecordgroup byorder - RubyRails
* ruby on rails - "Order by" result of "group by" count? - Stack Overflow

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 300dfaafed0051017960a2b6920dc9ed