2015-10-15 70 views
0

说我有以下计划环回查询,其比较字段值

Product: { 
    Quantity: Number, 
    SelledQuantity: Number 
} 

是否可以写,所有的结果返回的查询在哪里Quantity=SelledQuantity

如果是这样,有没有办法使用它时做一个填充? (也许在opts对象的匹配字段内?)

我使用mysql连接器。

+0

您正在使用哪个连接器? – superkhau

+0

我使用mysql连接器 – irocker

回答

0

这个问题更关系到MySQL查询。但你可以通过javascript实现如下:

Product.find({}, fuction(err, products) { 
    if(err) throw err; 

    //considering products as array of product. Otherwise you can get to depth for array of product. 
    var filteredProducts = products.filter(function(p1) { 
     return p1.Quantity === p1.SelledQuantity; 
    }); 

    //Your desired output 
    console.log(filteredProducts); 
}); 

这将会很慢,但会适用于较小的数据库大小。要获得更多优化的答案,请在MySQL部分中提问关于数据库和表结构的问题。