MongoDB等效于
SELECT state, SUM(pop) AS totalPop
FROM zipcodes
GROUP BY state
HAVING totalPop >= (10*1000*1000)
是
db.zipcodes.aggregate( [
{ $group: { _id: "$state", totalPop: { $sum: "$pop" } } },
{ $match: { totalPop: { $gte: 10*1000*1000 } } }
] )
如何在涉及substr
操作的SQL查询中获取MongoDB等效项
SELECT substr(state,0,3), SUM(pop) AS totalPop
FROM zipcodes
GROUP BY substr(state,0,3)
HAVING totalPop >= (10*1000*1000)
答案 0 :(得分:1)