续集:如何使用组和计数(Sequel: How to use group and count)

2019-07-29 17:08发布

简单地说,我该怎么办使用此查询续集 ?

select a.id, count(t.id)
from albums a
right join tracks t on t.album_id = a.id
group by a.id

Answer 1:

DB[:albums___a].
  right_join(:tracks___t, :album_id=>:id).
  select_group(:a__id).
  select_more{count(:t__id)}


Answer 2:

你的问题是左连接查找每个相册ID的轨道ID。 解决方案:

right join

总和的子查询,假设续集支持: left join (select album_id, count(album_id) as count from tracks group by album_id) t on

一个海峡向上from albums a, tracks t where t.album_id=a.id代替加入。



文章来源: Sequel: How to use group and count