比如这是数据结构
{
_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只能单条件
2***@qq.com (作者)
好的,感谢,我去试一下的
2023-03-23 11:02