3 回答
湖上湖
TA贡献2003条经验 获得超2个赞
参考代码:
var pipeline =[
{
$match: {
sjbh: {$gte: beginDate, $lte:endDate}
}
},
{
$group: {
_id: "$gsbh",
totaltxl: {$sum: { $cond: { if: { $ne: [ "$totalnum","" ] }, then:"$txl" , else: 0 }}},
totalbmynum: {$sum: "$bmynum"}
}
},
{
$project: {
_id: 0,
gsbh: "$_id",
totaltxl: "$totaltxl",
totalbmynum: "$totalbmynum",
ratio: { $divide: [ "$totalbmynum", { $cond:{if: { $eq: [ "$totaltxl",0 ] }, then:1 , else: "$totaltxl" }}] }
}
},
{$sort: {ratio: -1}},
{$limit: 5}
{$skip : 5}
]
opts.dbs.csdb.collection("permydfx").aggregate(pipeline).......
- 3 回答
- 0 关注
- 1697 浏览
添加回答
举报
0/150
提交
取消