简单地说,我该怎么办使用此查询续集 ?
select a.id, count(t.id)
from albums a
right join tracks t on t.album_id = a.id
group by a.id
简单地说,我该怎么办使用此查询续集 ?
select a.id, count(t.id)
from albums a
right join tracks t on t.album_id = a.id
group by a.id
DB[:albums___a].
right_join(:tracks___t, :album_id=>:id).
select_group(:a__id).
select_more{count(:t__id)}
你的问题是左连接查找每个相册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
代替加入。