Sequel: How to use group and count

人盡茶涼 提交于 2019-12-04 05:20:42
DB[:albums___a].
  right_join(:tracks___t, :album_id=>:id).
  select_group(:a__id).
  select_more{count(:t__id)}

Your problem is that the left join finds a track ID for each album ID. Solutions:

right join

subquery of sums, assuming sequel supports that: left join (select album_id, count(album_id) as count from tracks group by album_id) t on

a strait up from albums a, tracks t where t.album_id=a.id instead of the join.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!