Open main menu

User:Ijon/Queries

Queries tutorialsEdit

Asaf's Query examplesEdit

Breakdown of item types (instance of) for a given country (Israel, here)Edit

The following query uses these:

  • Properties: country (P17)    , instance of (P31)    
     1 # breakdown of item types (instance of) for a given country (Israel, here)
     2 SELECT ?instanceLabel (COUNT(?item) as ?count) 
     3 WHERE { 
     4   ?item wdt:P17 wd:Q801 . 
     5   ?item wdt:P31 ?instance . 
     6   ?instance rdfs:label ?instanceLabel  
     7   FILTER(LANG(?instanceLabel) = "he")
     8 }
     9 GROUP BY ?instanceLabel
    10 ORDER BY DESC(?count)
    11 LIMIT 30
    

Albums known to be from a certain country (Israel, here)Edit

The following query uses these:

Ukrainian politicians by birth oblastEdit

The following query uses these:

People born somewhere in Zhytomyr oblast, with fallback languages markedEdit

The following query uses these:

  • Properties: instance of (P31)    , place of birth (P19)    , located in the administrative territorial entity (P131)    
     1 # People born somewhere in Zhytomyr oblast, with fallback languages marked
     2 SELECT ?shtuka ?shtukaLabel (LANG(?shtukaLabel) as ?lang) 
     3 WHERE 
     4 {
     5   { ?shtuka wdt:P31 wd:Q5 . # all the humans
     6   ?shtuka wdt:P19 ?place . # who have a place of birth
     7   
     8   ?place wdt:P131 wd:Q40637 .} # which is in Zhytomyr oblast
     9   
    10   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ru,pl,be,cs,bg,sr,en". }
    11 }
    

Editors-in-chief and their employersEdit

The following query uses these:

  • Properties: instance of (P31)    , position held (P39)    , employer (P108)    
     1 # Editors-in-chief and their employers
     2 SELECT ?editor ?editorLabel ?empLabel
     3 WHERE 
     4 {
     5   ?editor wdt:P31 wd:Q5.
     6   ?editor wdt:P39 wd:Q589298 . # holding editor-in-chief positions
     7   OPTIONAL {
     8             ?editor p:P39 ?prop .
     9            ?prop ps:P39 wd:Q589298 .
    10            ?prop pq:P108 ?emp . }
    11   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    12 }
    

Best-described items in Te Papa museumEdit

The following query uses these:

  • Properties: collection (P195)    , location (P276)    , instance of (P31)    
    1 # best-described items in Te Papa museum
    2 SELECT DISTINCT ?q ?stcount WHERE {
    3   { ?q wdt:P195 wd:Q915603 .} # in Te Papa's collection 
    4   UNION 
    5   { ?q wdt:P276 wd:Q915603 .} # or "located in" Te Papa }
    6   # ?q wdt:P31 wd:Q3305213 . # limit to paintings (to not timeout)
    7   ?q wikibase:statements ?stcount .
    8 } GROUP BY ?q ?stcount
    9 ORDER BY DESC(?stcount)
    

Most-used properties to describe poemsEdit

The following query uses these:

  • Properties: instance of (P31)    
     1 SELECT ?prop ?propLabel ?count 
     2 WHERE 
     3 {
     4     {
     5         SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {
     6            
     7            hint:Query hint:optimizer "None" .
     8            ?item wdt:P31 wd:Q5185279 .
     9            ?item ?p ?id .
    10            ?prop wikibase:directClaim ?p .
    11         }  GROUP BY ?prop
    12     }
    13   
    14     SERVICE wikibase:label {
    15         bd:serviceParam wikibase:language "en" .
    16     }
    17 } ORDER BY DESC (?count)
    

People who won the Nobel Prize more than onceEdit

The following query uses these:

  • Properties: instance of (P31)    , award received (P166)    
     1 # People who won the Nobel Prize more than once
     2 SELECT ?winnerLabel ?wins
     3 {
     4   {
     5     SELECT ?winner (COUNT(?prize) AS ?wins)
     6     WHERE  
     7     { 
     8       ?winner wdt:P31 wd:Q5 . # human
     9       ?winner wdt:P166 ?prize . # who has won some prize
    10       ?prize wdt:P31 wd:Q7191 . # and where that prize is a kind of Nobel prize
    11     }
    12     GROUP BY ?winner
    13     ORDER BY DESC(?wins)
    14   }
    15   FILTER( ?wins > 1)
    16   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    17 }
    

Model items by typeEdit

The following query uses these:

  • Properties: model item (P5869)    
    1 # model items
    2 SELECT ?conceptLabel ?item ?itemLabel 
    3 WHERE 
    4 {
    5   ?concept wdt:P5869 ?item.
    6   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    7 } ORDER BY ?conceptLabel
    

Queries Asaf is too lazy to paste hereEdit

Other people's queries to stealadaptEdit