湖上湖
参考代码: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).......