Aggregate query with where condition

前端 未结 2 1618
别跟我提以往
别跟我提以往 2021-02-19 05:40

How could the following SQL query be converted for Mongo:

SELECT KeyID, SUM(Qty)
FROM Table
WHERE Date <= \'1998-12-01         


        
2条回答
  •  庸人自扰
    2021-02-19 05:54

    Something like:

    db.myTable.aggregate([
      { $match: { mydate: { $lte: new Date('12/01/1998') } } },
      { $group: {
        _id: "$keyid",
        totalqty: { $sum: "$qty" }
      }}
    ])
    

提交回复
热议问题