285679784@qq.com
285679784@qq.com
  • 发布:2021-06-11 10:20
  • 更新:2021-06-11 10:20
  • 阅读:34

uniCloud clientDB,使用groupby分组统计,求每个商品的合计金额

分类:uniCloud

{
data: [{
name: "商品1",
amount: 5,
price: 100
},{
name: "商品2",
amount: 5,
price: 200
},{
name: "商品3",
amount: 5,
price: 300
}]
}

#uniCloud clientDB,使用groupby分组统计,求每个商品的合计金额  
const res = await db.collection('orders')  
.groupBy('name')  
.groupField('sum(multiply(amount,price)) as total')  
.get()

返回结果如下

{
data: [{
name: "商品1",
total:500
},{
name: "商品2",
total:1000
},{
name: "商品3",
total:1500
}]
}

0 关注 分享

要回复文章请先登录注册