ActiveRecord sum 和 group by 对带有 sum 和 group by 的子查询进行求和和分组
我试图弄清楚如何在 Ruby ActiveRecord 中对执行第一级求和和分组的子查询进行求和和分组。
我可以使用命名范围和后续的选择函数来获取子查询的总和。它在一个循环中执行,该表为每笔付款构建一个包含一行的表,每个现金预付款组的顶部都有付款总额,以及所有辛迪加现金预付款的每个辛迪加组的总计:
@funder
.cashadvance_syndicators(@start_date, @end_date)
.select("sum(amount) as amount, percent_syndicated, management_fee, residual_commission")
.where(['cashadvance_syndicators.iso_id = ?', cs.iso_id])
.group('cashadvance_syndicators.id')
其中资助者
拥有许多现金预付款,向借款人提供许多付款,其中许多现金预付款银团根据整个贷款的百分比参与其中。
我需要能够汇总为每个辛迪加者选择的列中的金额。
I am trying to figure out how to sum and group on a sub-query that does a first level sum and group, in Ruby ActiveRecord.
I can get the sums of the sub-query using a named scope and a subsequent select function. That gets executed in a loop that builds a table with a row for each payment, with payment totals on the top of each cashadvance group, and totals for each syndicator group for all the syndicators cashadvances:
@funder
.cashadvance_syndicators(@start_date, @end_date)
.select("sum(amount) as amount, percent_syndicated, management_fee, residual_commission")
.where(['cashadvance_syndicators.iso_id = ?', cs.iso_id])
.group('cashadvance_syndicators.id')
where a funder
has many cashadvances, which has many payments to borrowers in which many cashadvance syndicators participate in based on a percent of the whole loan.
I need to be able to sum the amounts in the columns selected for each syndicator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论