与Alasql组的组中
我需要帮助来实现对象数组的这种转换。 我正在与Alasql合作。 我需要按玩家进行组。 我试过 alasql('从player中选择得分?在哪里得分组”,[arraygameplayerObjects])
但是我得到了这个结果
{
"player": {
"id": 5,
"firstName": "Player",
"lastName": "05",
"email": "[email protected]"
}
}
原始的对象:
[
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score": {"id": 5,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score": {"id": 6,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
},
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score": {"id": 7,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score": {"id": 8,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
}
我需要的最终结果是:
[
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score01": {"id": 5,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
},
"score02": {"id": 7,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score01": {"id": 6,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
},
"score02": {"id": 8,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
}
]
有关如何获得此结果的指南或想法?
I need help to achieve this transformation of an Array of Objects.
I am working with alaSQL.
I need to do a GroupBY by player.
I triedalasql('SELECT score FROM ? WHERE score GROUP BY player',[arrayGamePlayerObjects])
But I got this result
{
"player": {
"id": 5,
"firstName": "Player",
"lastName": "05",
"email": "[email protected]"
}
}
Original Array of Objects:
[
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score": {"id": 5,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score": {"id": 6,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
},
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score": {"id": 7,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score": {"id": 8,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
}
The end result I need is :
[
{
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"},
"score01": {"id": 5,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
},
"score02": {"id": 7,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 5,"firstName": "Player","lastName": "05","email": "[email protected]"}
}
},
{
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"},
"score01": {"id": 6,"score": 0.5,"finishDate": "2022-05-05T16:12:22.038+00:00",
"game": {"id": 3,"gameName": "Game 03","gameDate": "2022-05-05T18:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
},
"score02": {"id": 8,"score": 0.5,"finishDate": "2022-05-05T16:12:22.042+00:00",
"game": {"id": 6,"gameName": "Game 06","gameDate": "2022-05-05T20:12:21.049+00:00"},
"player": {"id": 6,"firstName": "Player","lastName": "06","email": "[email protected]"}
}
}
]
Any guide or ideas on how to get this result ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这会有所帮助!
实施
用法
输出
参考:
I think this can help!
Implementation
Usage
Output
Ref: from
我在此查询中使用了Alasql,并且可以正常工作。
I used alaSQL with this query and works Ok .