I want to calculate the percentage of the position of a football player field-wise to the country they belong to.
Let’s say, there are a total 800 players from Nepal whereas only 20 were goal keepers so percentage would be Nepal: 2.5 %
My Dataset
[{
"position":"defenser",
"country":"Nepal"
},
{
"position":"defenser",
"country":"Nepal"
},
{
"position":"goal keeper",
"country":"Nepal"
},
{
"position":"goal keeper",
"country":"France"
},
{
"position":"defenser",
"country":"France"
},
{
"position":"goal keeper",
"country":"France"
},
{
"position":"defenser",
"country":"France"
},
{
"position":"defenser",
"country":"Nepal"
}
]
there are 3 defenser from Nepal out of total 4 and 2 defenser from france out of 4.
Expected output
:
{"country":"Nepal", "position": "defenser", "percentage":"75"}
{"country":"France", "position": "defenser", "percentage":"50"}
2
Answers
As far as this data set and the problem is concerned we can get the appropriate result without using $$ROOT and $replaceRoot functions too.
Solution:
3 Then multiple groups of country and positions and there individual sum.
4 In last project stage calculate the percentage
Query
Playmongo