SPARQL examples

From Wer Leitet?
Revision as of 14:12, 5 August 2024 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Persons

Persons ordered by city with additional information if available

SELECT ?city ?person ?personLabel ?birthDate ?birthPlace ?occupation ?mainInfo WHERE {
  ?person rdfs:label ?personLabel;
     wdt:P3 wd:Q2; 
OPTIONAL {?person wdt:P381 ?city.}
OPTIONAL {?person wdt:P626 ?birthDate.}
OPTIONAL {?person wdt:P349 ?birthPlace.}
OPTIONAL {?person wdt:P999 ?occupation.}
OPTIONAL {?person wdt:P253 ?mainInfo.}
FILTER((LANG(?personLabel)) = "de")
} ORDER BY ?city

Persons in advisory boards in a time range

SELECT DISTINCT ?person ?personLabel ?beirat WHERE {
  ?person rdfs:label ?personLabel;
     wdt:P3 wd:Q2; 
     wdt:P463 ?surname;
     p:P1012 [ps:P1012 ?beirat;
              pq:P4 ?pubDate].
FILTER((LANG(?personLabel)) = "de")
FILTER("1940-01-01"^^xsd:dateTime <= ?pubDate && ?pubDate < "1941-01-01"^^xsd:dateTime).
} ORDER BY ?surname

Count of occupations

SELECT DISTINCT (COUNT (?person) as ?noPeople) ?occupation WHERE {
 ?person wdt:P3 wd:Q2;
             wdt:P999 ?occupation.
 }
GROUP BY ?occupation HAVING (?noPeople  > 1)
ORDER BY DESC(?noPeople)