我想根据时间date查询数据库,在查询到的数据中,busNo相同的情况下,把data里的值相加。这要怎么写查询语句呢
1 回答
慕先生3293204
TA贡献1条经验 获得超1个赞
db.bus_alarm_stat.aggregate(
[{ $project: {
"busNo": "$busNo","groupId" :"$groupId","date":"$date","DANGEROUS_DRIVE":"$data.DANGEROUS_DRIVE","FATIGUE_DRIVE" : "$data.FATIGUE_DRIVE",
"OUT_AREA":"$data.OUT_AREA"}
},{$match:{"date":{"$gte": "2017-07-23","$lte": "2017-07-25"}}},{"$group":{_id:"$busNo",
DANGEROUS_DRIVE:{"$sum":"$DANGEROUS_DRIVE"},
FATIGUE_DRIVE:{"$sum":"$FATIGUE_DRIVE"},
OUT_AREA:{"$sum":"$OUT_AREA"},
}
}
]
);
自己把它解决啦
- 1 回答
- 1 关注
- 1933 浏览
添加回答
举报
0/150
提交
取消