如何在 Rails 中执行此操作?:
select avg(cnt)
from
(
select
count(*) as cnt
from
sngs s
inner join clbs c on c.id = s.clb_id
where
c.user_id = 35
group by
date(s.record_date)
) sc
线
current_user.sngs.joins(:clb).average("count(*)", group: "date(record_date)")
给出一个错误:
PG::Error: 错误:聚合函数调用不能嵌套第 1 行:SELECT AVG(count(*)) ......