让这两个简单的 JSON 文件
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"
}
}
我想编写一个 JSONiq 查询,根据他的 screen_name 为每个用户确定他有多少条推文,这个例子的预期输出是
{ "2" : "ifp_tuebingen" }{ "1" : "ifp_reutlingen" }
我写了以下代码
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}
它会产生以下输出
{ "1" : "ifp_tuebingen" }{ "1" : "ifp_tuebingen" }{ "1" : "ifp_reutlingen" }