2***@qq.com
2***@qq.com
  • 发布:2023-03-18 12:17
  • 更新:2023-03-20 13:56
  • 阅读:130

请问groupField只能单条件统计吗?

分类:uniCloud

比如这是数据结构

{  
  _id: "1",  
  grade: "1",  
  class: "A",  
  name: "zhao",  
  score: 5  
}  
{  
  _id: "2",  
  grade: "1",  
  class: "A",  
  name: "qian",  
  score: 15  
}  
{  
  _id: "3",  
  grade: "1",  
  class: "B",  
  name: "li",  
  score: 15  
}  
{  
  _id: "4",  
  grade: "1",  
  class: "B",  
  name: "zhou",  
  score: 25  
}  
{  
  _id: "5",  
  grade: "2",  
  class: "A",  
  name: "wu",  
  score: 25  
}  
{  
  _id: "6",  
  grade: "2",  
  class: "A",  
  name: "zheng",  
  score: 35  
}  

官方文档的用法是 groupField('sum(score) as totalScore')

const res = await db.collection('score').groupBy('grade,class')  
.groupField('sum(score) as totalScore')  
.get()  

想达到的效果是 groupField('sum(score) as totalScore && avg(score) as avgScore')
即:同时求和 并 求均 或者 同时求和 并 统计

const res = await db.collection('score').groupBy('grade,class')  
.groupField('sum(score) as totalScore  && avg(score) as avgScore')  
.get()  

可以同时这样写吗?

还是 groupField只能单条件

2023-03-18 12:17 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

&&改成逗号

  • 2***@qq.com (作者)

    好的,感谢,我去试一下的

    2023-03-23 11:02

要回复问题请先登录注册