我的查询是mysql如下:
SELECT SUM(nbdownloaded) FROM (
SELECT field1, field2, nbdownloaded
FROM mytable
Where ....
) as reports
在rails中,我将子查询的结果变为变量。
比如我说:
my_reports = Reports.group("id").select("field1, field2, sum(field3) as nbdownloaded").where(...)")
我希望得到字段nbdownloaded的总和。
谢谢
答案 0 :(得分:0)
在rails活动记录查询中非常容易,
Model.sum(:nbdownloaded).where(:column =>'your condition')