J'ai le fichier JSON suivant:
"spells": [
{
"spell":"Aberto",
"effect":"opens objects",
"_id":"5b74ebd5fb6fc0739646754c",
"type":"Charm"
},
{
"spell":"Accio",
"effect":"Summons an object",
"__v":0,
"_id":"5b74ecfa3228320021ab622b",
"type":"Charm"
},
{
"spell":"Age Line",
"effect":"Hides things from younger people",
"__v":0,
"_id":"5b74ed2f3228320021ab622c",
"type":"Enchantment"
},
{
"spell":"Aguamenti",
"effect":"shoots water from wand",
"__v":0,
"_id":"5b74ed453228320021ab622d",
"type":"Charm"
},
{
"spell":"Alarte Ascendare",
"effect":"shoots things high in the air",
"__v":0,
"_id":"5b74ed583228320021ab622e",
"type":"Spell"
}
}
Pouvez-vous m'aider à compter tous les sorts avec XQuery où le "type" = "Spell" et séparément tous les sorts où le "Type" = "charme". Le fichier JSON est beaucoup plus volumineux, je ne voulais tout simplement pas coller ici tout le fichier. Je vous remercie.
Cela semble être un regroupement et un comptage simples:
declare variable $spell-types as xs:string* external := ('Spell', 'Charm');
for $spell in ?spells?*[?type = $spell-types]
group by $t := $spell?type
return $t || ' : ' || count($spell)
https://xqueryfiddle.liberty-development.net/nc4P6y2
Ou, comme l'a souligné Michael Kay, avec une séquence de valeurs donnée, il suffit d'utiliser
for $spell-type in $spell-types
return $spell-type || ' : ' || count(?spells?*[?type = $spell-type])
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras