mongodb group by where
SELECT doctor_id,
SUM(num) as total
FROM statics
WHERE doctor_id>0
GROUP BY doctor_id
HAVING total > 250
db.statics.aggregate(
{ $match: { "doctor_id" :{ "$gt" : 0 } }},
{
$group: {
_id: "$doctor_id",
total: { $sum: "$num" }
} },
{ $match: { total: { $gt: 0 } } }
);
评论