如何根据sid获取总分?
输入如下:
[
{
"sid": 101,
"sname": "Rahul",
"sem": 1,
"marks": 9
},
{
"sid": 102,
"sname": "Rahul",
"sem": 2,
"marks": 9.5
},
{
"sid": 102,
"sname": "Rahul",
"sem": 3,
"marks": 8
},
{
"sid": 101,
"sname": "Rahul",
"sem": 4,
"marks": 7
}
]
我需要根据SID属性获取标记总数。
Input is as follows:
[
{
"sid": 101,
"sname": "Rahul",
"sem": 1,
"marks": 9
},
{
"sid": 102,
"sname": "Rahul",
"sem": 2,
"marks": 9.5
},
{
"sid": 102,
"sname": "Rahul",
"sem": 3,
"marks": 8
},
{
"sid": 101,
"sname": "Rahul",
"sem": 4,
"marks": 7
}
]
I need to get the total number of marks based on the sid attribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按SID对每个SID总和进行分组。
输出:
请注意,如果您要使用此信息进行进一步处理,则将输出到Application/Java而不是JSON更有效。
另外,如果您希望有一个每个SID的列表,则可以使用Pluck()。
输出:
You can group by the sid then for each sid sum all the marks.
Output:
Note that if you are going to use this information for further processing it will be more efficient to output to application/java instead of JSON.
Alternatively if you prefer to have a list with one element per sid you can use pluck().
Output: