Let be those two simple JSON files
jsoniq version "1.0";
let $tweets :=
{
{ "screen_name": "ifp_tuebingen"
},
{ "screen_name": "ifp_tuebingen"
},
{ "screen_name": "ifp_reutlingen"
}
}
let $users :=
{
{ "screen_name": "ifp_tuebingen"
},
{ "screen_name": "ifp_reutlingen"
}
}
I want to write a JSONiq query that determines for each user, how many tweets does he have based on his screen_name, an expected output for this example is
{ "2" : "ifp_tuebingen" }{ "1" : "ifp_reutlingen" }
I wrote the following code
for $u in $users
let $counter := 0
for $t in $tweets
where $u.screen_name eq $t.screen_name
let $counter := $counter+1
return {$counter : $u.screen_name}
it produces the following output instead
{ "1" : "ifp_tuebingen" }{ "1" : "ifp_tuebingen" }{ "1" : "ifp_reutlingen" }