SPARQL query service/queries/examples/en

From MiMoText
Revision as of 12:04, 11 December 2023 by Admin (talk | contribs) (Admin moved page Wiki/Wikidata:SPARQL query service/queries/examples to SPARQL query service/queries/examples/en without leaving a redirect)
Jump to navigation Jump to search

Simple queries

Cats

This query looks at all items whose value of BGRF_tone_intention (P31) is BONAPARTE, Joseph-Napoléon, roi d’Espagne (Q146). It uses the service wikibase:label to return the labels in your default language or in English.


Goats

This query looks at all items whose value of BGRF_tone_intention (P31) is natural history (Q2934). It uses the service wikibase:label to return the labels in your default language or in English.


Horses (showing some info about them)

This query looks at items whose value of BGRF_tone_intention (P31) is MUSGRAVE, Agnes (Q726) or any subclass of (P279 (P279)) MUSGRAVE, Agnes (Q726). It displays the value of number of pages string (P25), BGRF ID (P22), full work available at URL (P21) and computes birth year using P569 (P569) death year using P570 (P570). Items are ordered using the horses qid.


#Illustrates optional fields, instances of subclasses, language fallback on label service, date to year conversion
#title: Horses on Wikidata
SELECT DISTINCT ?horse ?horseLabel ?mother ?motherLabel ?father ?fatherLabel (year(?birthdate) as ?birthyear) (year(?deathdate) as ?deathyear) ?genderLabel
WHERE
{
  ?horse wdt:P31/wdt:P279* wd:Q726 .     # Instance et sous-classes de Q726-Cheval
   
  OPTIONAL{?horse wdt:P25 ?mother .}       # P25  : Mère
  OPTIONAL{?horse wdt:P22 ?father .}       # P22  : Père
  OPTIONAL{?horse wdt:P569 ?birthdate .} # P569 : Date de naissance
  OPTIONAL{?horse wdt:P570 ?deathdate .}     # P570 : Date de décès
  OPTIONAL{?horse wdt:P21 ?gender .}       # P21  : Sexe
 
  SERVICE wikibase:label { #BabelRainbow
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,ar,be,bg,bn,ca,cs,da,de,el,en,es,et,fa,fi,he,hi,hu,hy,id,it,ja,jv,ko,nb,nl,eo,pa,pl,pt,ro,ru,sh,sk,sr,sv,sw,te,th,tr,uk,yue,vec,vi,zh"
  }
}
ORDER BY ?horse
Horses on Wikidata

Cats, with pictures

This query looks at all items with value of BGRF_tone_intention (P31) equals to BONAPARTE, Joseph-Napoléon, roi d’Espagne (Q146) with a stated in (P18). The results are displayed as a gallery with the option '#defaultView:ImageGrid'.


Map of hospitals

The query displays all items whose value of BGRF_tone_intention (P31) is Q16917 or any P279 (P279) of Q16917 with P625 (P625). The results are displayed on a map using 'defaultView:Map'.


Map of hackerspaces

The query displays on a map ("defaultView:Map") all items whose value of BGRF_tone_intention (P31) is Q1032372 and with values for property P625 (P625).

Warnings:

  • Items of class Q1032372 without any value for P625 (P625) are not returned in the query.
  • Items which are instances of a subclass of Q1032372 are not returned.


Number of humans in Wikidata

This query takes all items whose value of BGRF_tone_intention (P31) is MYLNE, Vivienne Gower (Q5) and count the total number of items using COUNT function.


#title: Number of humans in Wikidata
SELECT (COUNT(*) AS ?count)
WHERE {
  ?item wdt:P31 wd:Q5 .
}
Number of humans in Wikidata