3
我有以下的mysql查询,其中我已经完成了两个不同的字段,称为“count”和“population”,然后划分sum(count)/总和(人口),然后乘以100000,最后按年分组。如何在单独的mongodb查询中使用求和,乘法,除法和组合
Select year, cname, (sum(count)/sum(population))*100000 as total from cancer c where c.cname ="lung and bronchus" group by year;
我在mongodb中写了下面的查询,但我不知道如何投影cname和year。
db.cancer_stats.aggregate([
{$match:{cname: "lung and bronchus"}},
{$group:{_id:"year"},
{total:{$multiply:[$divide:[$sum:"$count", $sum:"population"], 100000]}}
}])
任何人都可以指导我解决这个查询吗?
谢谢你的回答;它正在执行但没有显示任何结果。它正在显示 {“result”:[],“ok”:1} – Yash 2014-12-08 20:32:21
这是什么意思? – Yash 2014-12-08 20:38:01