Wikidata:SPARQL query service/queries/examples

From Wikidata
Jump to: navigation, search

This page is parsed by the web interface of the query service to fill the query example dialog.

Consider adding a comment in the query noting what it illustrates, when and by whom it was written and which are its limitations given the current data and use of properties at Wikidata.

Contents

See also[edit]

Simple Queries[edit]

These basic queries help to understand w:SPARQL and the Wikibase RDF format.

Cats[edit]

The following query uses these:

SELECT ?item ?itemLabel
WHERE
{
	?item wdt:P31 wd:Q146 .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Horses[edit]

The following query uses these:

#added before 2016-10
#Illustrates optional fields, instances of subclasses, language fallback on label service, date to year conversion
# Chevaux sur Wikidata
SELECT DISTINCT ?cheval ?chevalLabel ?mere ?pere (year(?naissance) as ?Naissance) (year(?deces) as ?Décès) ?sexeLabel
WHERE
{
	?cheval wdt:P31/wdt:P279* wd:Q726 .     # Instance et sous-classes de Q726-Cheval
	  
	OPTIONAL{?cheval wdt:P25 ?mere .}       # P25  : Mère
	OPTIONAL{?cheval wdt:P22 ?pere .}       # P22  : Père
	OPTIONAL{?cheval wdt:P569 ?naissance .} # P569 : Date de naissance
	OPTIONAL{?cheval wdt:P570 ?deces .}     # P570 : Date de décès
	OPTIONAL{?cheval wdt:P21 ?sexe .}       # P21  : Sexe
  
	SERVICE wikibase:label { #BabelRainbow
		bd:serviceParam wikibase: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 ?cheval

Try it!

Wikidata items with a Wikispecies sitelink[edit]

#added before 2016-10
#illustrates sitelink selection, ";" notation
SELECT ?item ?itemLabel ?article
WHERE
{
	?article 	schema:about ?item ;
			schema:isPartOf <https://species.wikimedia.org/> .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
LIMIT 200

Try it!


Wikidata items about authors with a Wikispecies page[edit]

SELECT ?author ?authorLabel (COUNT(?paper) AS ?count)
WHERE
{
	?article 	schema:about ?author ;
			schema:isPartOf <https://species.wikimedia.org/> .
    ?author wdt:P31 wd:Q5.
    ?paper wdt:P50 ?author.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?author ?authorLabel
ORDER BY DESC(?count)
LIMIT 200

Try it!

Recent Events[edit]

The following query uses these:

SELECT ?event ?eventLabel ?date
WHERE
{
	# find events
	?event wdt:P31/wdt:P279* wd:Q1190554.
	# with a point in time or start date
	OPTIONAL { ?event wdt:P585 ?date. }
	OPTIONAL { ?event wdt:P580 ?date. }
	# but at least one of those
	FILTER(BOUND(?date) && DATATYPE(?date) = xsd:dateTime).
	# not in the future, and not more than 31 days ago
	BIND(NOW() - ?date AS ?distance).
	FILTER(0 <= ?distance && ?distance < 31).
	# and get a label as well
	OPTIONAL {
		?event rdfs:label ?eventLabel.
		FILTER(LANG(?eventLabel) = "en").
	}
}
# limit to 10 results so we don't timeout
LIMIT 10

Try it!

Popular eye colors[edit]

The following query uses these:

#added before 2016-10
#illustrates bubblechart view, count

#defaultView:BubbleChart
SELECT ?eyeColorLabel (COUNT(?person) AS ?count)
WHERE
{
	?person wdt:P1340 ?eyeColor.
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?eyeColorLabel

Try it!

Even more cats, with pictures[edit]

The following query uses these:

#added before 2016-10

#defaultView:ImageGrid
SELECT ?item ?itemLabel ?pic
WHERE
{
	?item ?prop wd:Q146 . 
	OPTIONAL {
		?item wdt:P18 ?pic
	} 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

People whose gender we know we don't know[edit]

The following query uses these:

#added before 2016-10
#Demonstrates "unknown value" handling
SELECT ?human ?humanLabel
WHERE
{
	?human wdt:P21 ?gender
	FILTER isBLANK(?gender) .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Humans without children[edit]

In the simplest form: The following query uses these:

#added before 2016-10
#Demonstrates "no value" handling
SELECT ?human ?humanLabel
WHERE
{
	?human wdt:P31 wd:Q5 .       #find humans
	?human rdf:type wdno:P40 .   #with at least one P40 (child) statement defined to be "no value"
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

An equivalent query (slightly more verbose):

SELECT ?human ?humanLabel {
  ?human wdt:P31 wd:Q5 .         #find humans
  ?human p:P40 ?childStatement . #with at least one P40 (child) statement
  ?childStatement a wdno:P40 .   #where the P40 (child) statement is defined to be "no value"
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!

URLs of Wikipedia in all languages[edit]

This query provides an alternative to scraping the Wikipedia.org portal page and various lists/tables of Wikipedias that are out there.

PREFIX schema: <http://schema.org/>

SELECT ?sitelink
WHERE {
  BIND(wd:Q52 AS ?wikipedia)
  ?sitelink schema:about ?wikipedia .
  FILTER REGEX(STR(?sitelink), ".wikipedia.org/wiki/") .
}

Try it!

Showcase Queries[edit]

These queries show the power and functionality of SPARQL and WDQS GUI.

Largest cities with female mayor[edit]

#added before 2016-10
#TEMPLATE={"template":"Largest ?c with ?sex head of government","variables":{"?sex":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q48264 .  } "},"?c":{"query":"SELECT DISTINCT ?id WHERE {  ?c wdt:P31 ?id.  ?c p:P6 ?mayor. }"} } }
SELECT DISTINCT ?city ?cityLabel ?mayor ?mayorLabel 
WHERE 
{
  BIND(wd:Q6581072 AS ?sex)
  BIND(wd:Q515 AS ?c)

	?city wdt:P31/wdt:P279* ?c .  # find instances of subclasses of city
	?city p:P6 ?statement .            # with a P6 (head of goverment) statement
	?statement ps:P6 ?mayor .          # ... that has the value ?mayor
	?mayor wdt:P21 ?sex .       # ... where the ?mayor has P21 (sex or gender) female
	FILTER NOT EXISTS { ?statement pq:P582 ?x }  # ... but the statement has no P582 (end date) qualifier
	 
	# Now select the population value of the ?city
	# (wdt: properties use only statements of "preferred" rank if any, usually meaning "current population")
	?city wdt:P1082 ?population .
	# Optionally, find English labels for city and mayor:
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}
ORDER BY DESC(?population)
LIMIT 10

Try it!

List of countries ordered by the number of their cities with female mayor[edit]

#added before 2016-10
SELECT ?country ?countryLabel (count(*) AS ?count) 
WHERE 
{
	?city wdt:P31/wdt:P279* wd:Q515 . # find instances of subclasses of city
	?city p:P6 ?statement .           # with a P6 (head of goverment) statement
	?statement ps:P6 ?mayor .         # ... that has the value ?mayor
	?mayor wdt:P21 wd:Q6581072 .      # ... where the ?mayor has P21 (sex or gender) female
	FILTER NOT EXISTS { ?statement pq:P582 ?x }  # ... but the statement has no P582 (end date) qualifier
	?city wdt:P17 ?country .          # Also find the country of the city
 	
	# If available, get the "ru" label of the country, use "en" as fallback:
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "ru,en" .
	}
} 
GROUP BY ?country ?countryLabel 
ORDER BY DESC(?count) 
LIMIT 100

Try it!

Popular surnames among humans[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?surname ?surnameLabel ?count
WHERE
{
  {
    SELECT ?surname (COUNT(?person) AS ?count) WHERE {
      ?person wdt:P31 wd:Q5.
      ?person wdt:P734 ?surname.
    }
    GROUP BY ?surname
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)
LIMIT 100

Try it!

Given names with most variations[edit]

#added before 2016-10

SELECT ?name (COUNT(?otherName) AS ?count)
WHERE
{
  ?name wdt:P31 wd:Q202444;
        wdt:P460 ?otherName.
}
GROUP BY ?name
ORDER BY DESC(?count)
LIMIT 10

Try it!

Popular surnames among fictional characters[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?surname ?surnameLabel ?count
WHERE
{
  {
    SELECT ?surname (COUNT(?person) AS ?count) WHERE {
      ?person (wdt:P31/wdt:P279*) wd:Q95074.
      ?person wdt:P734 ?surname.
    }
    GROUP BY ?surname
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)
LIMIT 100

Try it!

Women with most sitelinks and no image born in 1921 or later[edit]

#added before 2016-10

SELECT ?s ?desc (COUNT(DISTINCT ?sitelink) as ?linkcount)
WHERE
{
  ?s wdt:P31 wd:Q5 .
  ?s wdt:P21 wd:Q6581072 .
  ?s wdt:P569 ?born .
  FILTER (?born >= "1921-01-01T00:00:00Z"^^xsd:dateTime) .
  ?sitelink schema:about ?s .
  OPTIONAL {
    ?s wdt:P18 ?dummy
  }
  FILTER ( !bound(?dummy) ) .
  OPTIONAL {
     ?s rdfs:label ?desc filter (lang(?desc) = "en").
   }
}
GROUP BY ?s ?desc 
ORDER BY DESC(?linkcount)
LIMIT 50

Try it!

Bubble charts[edit]

Overall causes of death ranking[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?cid ?cause (count(*) as ?count)
WHERE
{
	?pid wdt:P31 wd:Q5 .
	?pid wdt:P509 ?cid .
	OPTIONAL {
		?cid rdfs:label ?cause 
		filter (lang(?cause) = "en")
	}
}
GROUP BY ?cid ?cause
ORDER BY DESC(?count) ASC(?cause)

Try it!

WWII battle durations[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT DISTINCT ?item ?itemLabel (?end - ?start AS ?duration)
WHERE
{
	?item wdt:P361* wd:Q362 .
	?item wdt:P31/wdt:P279* wd:Q178561 .
	?item wdt:P580 ?start .
	?item wdt:P582 ?end .

	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Timeline[edit]

Timeline of space probes[edit]

#defaultView:Timeline
SELECT ?item ?itemLabel ?launchdate (SAMPLE(?image) AS ?image)
WHERE
{
	?item wdt:P31 wd:Q26529 .
    ?item wdt:P619 ?launchdate .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
    OPTIONAL { ?item wdt:P18 ?image }
}
GROUP BY ?item ?itemLabel ?launchdate

Try it!

Timeline of compositions by Wolfgang Amadeus Mozart[edit]

#defaultView:Timeline
SELECT DISTINCT  ?item ?itemLabel ?catalog_code ?publication_data
WHERE
{
	?item wdt:P86 wd:Q254 ;
          wdt:P528 ?catolog_code ;
          wdt:P577 ?publication_data .
    
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Dimensions[edit]

Dimensions of elements[edit]

#defaultView:Dimensions
SELECT ?elementLabel ?_boiling_point ?_melting_point ?_electronegativity ?_density ?_mass WHERE {
  ?element wdt:P31 wd:Q11344;
   wdt:P2102 ?_boiling_point;
   wdt:P2101 ?_melting_point;
   wdt:P1108 ?_electronegativity;
   wdt:P2054 ?_density;
   wdt:P2067 ?_mass. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 100

Try it!

Graph[edit]

Children of Genghis Khan[edit]

#added before 2016-10
 #defaultView:Graph
PREFIX gas: <http://www.bigdata.com/rdf/gas#>

SELECT ?item ?itemLabel ?pic ?linkTo
WHERE
{
  SERVICE gas:service {
    gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.SSSP" ;
                gas:in wd:Q720 ;
                gas:traversalDirection "Forward" ;
                gas:out ?item ;
                gas:out1 ?depth ;
                gas:maxIterations 4 ;
                gas:linkType wdt:P40 .
  }
  OPTIONAL { ?item wdt:P40 ?linkTo }
  OPTIONAL { ?item wdt:P18 ?pic }
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}

Try it!

Music genres[edit]

#added before 2016-10
 
#defaultView:Graph
SELECT ?item ?itemLabel ?_image ?_subclass_of ?_subclass_ofLabel
WHERE
{
  ?item wdt:P31 wd:Q188451.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  OPTIONAL { ?item wdt:P279 ?_subclass_of. }
  OPTIONAL { ?item wdt:P18 ?_image. }
}

Try it!

Line chart[edit]

Average number of children per year[edit]

The following query uses these:

#defaultView:LineChart
SELECT  (str(?year) AS ?year) (AVG( ?_number_of_children ) AS ?count) WHERE {
  ?item wdt:P31 wd:Q5.
  ?item wdt:P1971 ?_number_of_children.
  ?item wdt:P569 ?_date_of_birth.
  BIND( year(?_date_of_birth) as ?year ).
  FILTER( ?year > 1900)
}

GROUP BY ?year

Try it!


Population of countries sharing a border with Germany[edit]

The following query uses these:

#defaultView:LineChart
SELECT ?country  ?year ?population ?countryLabel WHERE {
  {
    SELECT ?country ?year (AVG(?population) AS ?population) WHERE {
      {
        SELECT ?country (str(YEAR(?date)) AS ?year) ?population WHERE {
          ?country wdt:P47 wd:Q183.
          ?country p:P1082 ?populationStatement.
          ?populationStatement ps:P1082 ?population.
          ?populationStatement pq:P585 ?date.
        }
      }
    }
    GROUP BY ?country ?year
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!


Number of books by year and genre[edit]

The following query uses these:

#defaultView:LineChart
SELECT ?year (COUNT(?_genre) AS ?count ) (SAMPLE(?_genreLabel) AS ?_genreLabel )  WHERE {
  ?item wdt:P31 wd:Q571.
  ?item wdt:P577 ?_publication_date.
  ?item wdt:P136 ?_genre.
  ?_genre rdfs:label ?_genreLabel.
  BIND(str(YEAR(?_publication_date)) AS ?year)
  FILTER((LANG(?_genreLabel)) = "en")
  
 FILTER (?_publication_date >= "2000-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_genreLabel ?year
HAVING (?count > 10)

Try it!

Number of bands by year and genre[edit]

The following query uses these:

#defaultView:LineChart
SELECT ?year (COUNT(?_genre) AS ?count)  (SAMPLE(?_genreLabel) AS ?_genreLabel)  WHERE {
  ?item wdt:P31 wd:Q215380.
  ?item wdt:P571 ?_date.
  ?item wdt:P136 ?_genre.
  ?_genre rdfs:label ?_genreLabel.
  BIND(str(YEAR(?_date)) AS ?year)
  FILTER((LANG(?_genreLabel)) = "en")
  FILTER(?_date >= "1960-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_genreLabel ?year
HAVING (?count > 10)

Try it!

Bar chart[edit]

Battles per year per country last 80 years[edit]

The following query uses these:

#defaultView:BarChart

SELECT(SAMPLE(?year) AS ?year) (COUNT(?_country) AS ?battles)  (SAMPLE(?_countryLabel) AS ?_countryLabel)  WHERE {
  ?subj wdt:P31 wd:Q178561.
  OPTIONAL { ?subj wdt:P580 ?d1. }
  OPTIONAL { ?subj wdt:P585 ?d2. }
  OPTIONAL { ?subj wdt:P582 ?d3. }
  BIND(IF(!BOUND(?d1), IF(!BOUND(?d2), ?d3, ?d2), ?d1) AS ?date)
  BIND(str(YEAR(?date)) AS ?year)
  ?subj wdt:P276 ?_loc.
  ?_loc wdt:P17 ?_country.
  ?_country rdfs:label ?_countryLabel.
  BIND((NOW()) - ?date AS ?distance)
  FILTER(BOUND(?year))
  FILTER((LANG(?_countryLabel)) = "en")
  FILTER((0 <= ?distance) && (?distance < 31 * 12 * 80))
}
GROUP BY ?year ?_country
ORDER BY ?_countryLabel

Try it!


Battles per year per continent and country last 80 years (animated)[edit]

The following query uses these:

#defaultView:BarChart
SELECT (SAMPLE(?_continentLabel) AS ?contient) (COUNT(?_country) AS ?battles) (SAMPLE(?_countryLabel) AS ?_countryLabel) (SAMPLE(?year) AS ?year)  WHERE {
  ?subj wdt:P31 wd:Q178561.
  OPTIONAL { ?subj wdt:P580 ?d1. }
  OPTIONAL { ?subj wdt:P585 ?d2. }
  OPTIONAL { ?subj wdt:P582 ?d3. }
  BIND(IF(!BOUND(?d1), IF(!BOUND(?d2), ?d3, ?d2), ?d1) AS ?date)
  BIND(str(YEAR(?date)) AS ?year)
  ?subj wdt:P276 ?_loc.
  ?_loc wdt:P17 ?_country.
  ?_country wdt:P30 ?_continent.
  ?_country rdfs:label ?_countryLabel.
  ?_continent rdfs:label ?_continentLabel.
  
  BIND((NOW()) - ?date AS ?distance)
  FILTER(BOUND(?year))
  FILTER((LANG(?_countryLabel)) = "en")
  FILTER((LANG(?_continentLabel)) = "en")
  FILTER((0 <= ?distance) && (?distance < 31 * 12 * 80))
}
GROUP BY ?year ?_country
ORDER BY ?_countryLabel

Try it!

Yearly Population stacked by country[edit]

The following query uses these:

#defaultView:BarChart
SELECT  ?year ?population ?objectLabel
WHERE
{
        ?object	wdt:P31 wd:Q6256 
        ;	p:P1082 ?populationStatement .
        ?populationStatement    ps:P1082 ?population
        ;	pq:P585 ?date .
        BIND(str(YEAR(?date)) AS ?year)
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }                
} 
ORDER BY ?year ?country

Try it!

Built power plants per year per country[edit]

The following query uses these:

#defaultView:BarChart
SELECT DISTINCT  (SAMPLE(?year) AS ?year) (COUNT(?_country) AS ?count) (SAMPLE(?_countryLabel) AS ?_countryLabel) WHERE {
  ?object (wdt:P31/wdt:P279*) wd:Q134447.
  BIND(str(YEAR(?_inception)) AS ?year)
  ?object wdt:P571 ?_inception.
  ?object wdt:P17 ?_country.
  ?_country rdfs:label ?_countryLabel.
  FILTER((LANG(?_countryLabel)) = "en")
}
GROUP BY ?year ?_country
ORDER BY ?_countryLabel

Try it!

Area chart[edit]

Cancer deaths per year and cancer type[edit]

The following query uses these:

#defaultView:AreaChart
SELECT ?cid (str(SAMPLE(?year)) AS ?year )  (COUNT(*) AS ?count)  ?cause WHERE {
  ?pid wdt:P31 wd:Q5.
  ?pid wdt:P509 ?cid.
  ?cid wdt:P279* wd:Q12078.
  
  OPTIONAL {
    ?cid rdfs:label ?cause.
    FILTER((LANG(?cause)) = "en")
  }
   ?pid wdt:P570 ?_date_of_death. 
  BIND ( YEAR(?_date_of_death) AS ?year )
  FILTER( BOUND(?cause)  )
  FILTER( BOUND(?year)  )
  FILTER( ?year > 1960 )
}
GROUP BY ?cid ?cause ?year

Try it!

Treemap[edit]

Popular television series (in treeview)[edit]

#added before 2016-10

#defaultView:TreeMap
SELECT ?show ?showLabel  ?season ?cleanSeasonLabel ?episode ?episodeLabel
WHERE 
{
	{
		BIND(wd:Q886 as ?show) .
		?season wdt:P361 ?show .
		?season rdfs:label ?_seasonLabel.
		FILTER((LANG(?_seasonLabel)) = "en")
		BIND(SUBSTR(?_seasonLabel, 0, STRLEN(?_seasonLabel)-23) AS ?cleanSeasonLabel)
		?episode wdt:P361 ?season .
	}  
	UNION 
	{
		BIND(wd:Q16538 as ?show) .
		?season wdt:P361 ?show .
		?season rdfs:label ?_seasonLabel.
		FILTER((LANG(?_seasonLabel)) = "en")
		BIND(SUBSTR(?_seasonLabel, 0, STRLEN(?_seasonLabel)-20) AS ?cleanSeasonLabel)
		?episode wdt:P361 ?season .
	}   
	UNION
	{
		BIND(wd:Q147235 as ?show) .
		?season wdt:P361 ?show .
		?season rdfs:label ?_seasonLabel.
		FILTER((LANG(?_seasonLabel)) = "en")
		BIND(CONCAT("S", SUBSTR(?_seasonLabel, 25)) AS ?cleanSeasonLabel)
		?episode wdt:P361 ?season .
	} 

	SERVICE wikibase:label {  bd:serviceParam wikibase:language "en" }
}

Try it!

Famous people in categorised into eye and hair color[edit]

#defaultView:TreeMap
SELECT ?eyes ?hairColorLabel (COUNT(?person) as ?count)
WHERE
{
	?person wdt:P1340 ?eyeColor.
    ?person wdt:P1884 ?hairColor.
    ?person wdt:P2048 ?height.
    ?eyeColor rdfs:label ?_eyeColorLabel.
    FILTER((LANG(?_eyeColorLabel)) = "en")
    BIND(CONCAT(?_eyeColorLabel, " eyes") AS ?eyes)
    
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?eyes ?hairColorLabel

Try it!

Scatter chart[edit]

Number of films by year and genre[edit]

The following query uses these:

#defaultView:ScatterChart
SELECT   ?year  (COUNT(?_genre) AS ?count ) (SAMPLE(?_genreLabel) AS ?label )  (?year as ?year_shown) WHERE {
  ?item wdt:P31 wd:Q11424.
  ?item wdt:P577 ?_publication_date.
  ?item wdt:P136 ?_genre.
  ?_genre rdfs:label ?_genreLabel.
  BIND(str(YEAR(?_publication_date)) AS ?year)
  FILTER((LANG(?_genreLabel)) = "en")
  
 FILTER (?_publication_date >= "2000-00-00T00:00:00Z"^^xsd:dateTime)
}
GROUP BY ?_genreLabel ?year
HAVING (?count > 30)

Try it!

Airports within 100km of Berlin[edit]

#added before 2016-10
 
#defaultView:Map
SELECT ?place ?placeLabel ?location
WHERE
{
  # Berlin coordinates
  wd:Q64 wdt:P625 ?berlinLoc . 
  SERVICE wikibase:around { 
      ?place wdt:P625 ?location . 
      bd:serviceParam wikibase:center ?berlinLoc . 
      bd:serviceParam wikibase:radius "100" . 
  } 
  # Is an airport
  ?place wdt:P31/wdt:P279* wd:Q1248784 .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" . 
  }
}

Try it!


Airports in Belgium[edit]

#added before 2016-10
 
#List of airports in Belgium
#defaultView:Map
SELECT DISTINCT ?airport ?coor ?range
WHERE
{
  ?airport wdt:P31 wd:Q1248784 ;
  ?range wd:Q31;
  wdt:P625 ?coor.
}

Try it!

Schools between San Jose, CA and Sacramento, CA[edit]

#added before 2016-10
 # Schools between San Jose, CA and Sacramento, CA
#defaultView:Map
SELECT * 
WHERE
{
  wd:Q16553 wdt:P625 ?SJloc .
  wd:Q18013 wdt:P625 ?SCloc .
  SERVICE wikibase:box {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:cornerWest ?SJloc .
      bd:serviceParam wikibase:cornerEast ?SCloc .
    }
  ?place wdt:P31/wdt:P279* wd:Q3914 .
}

Try it!

Whose birthday is today?[edit]

#Whose birthday is today?
SELECT ?entityLabel (YEAR(?date) as ?year) 
WHERE
{
    BIND(MONTH(NOW()) AS ?nowMonth)
    BIND(DAY(NOW()) AS ?nowDay)

    ?entity wdt:P569 ?date .
    FILTER (MONTH(?date) = ?nowMonth && DAY(?date) = ?nowDay)
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
    }
}
LIMIT 10

Try it!

Finding John and Sarah Connor[edit]

#added before 2016-10
 SELECT * WHERE {
  ?p wdt:P1080 wd:Q620588 .
  ?p rdfs:label ?pl .
  FILTER (lang(?pl) = "en") 
  ?p wdt:P25 ?m .
  ?m rdfs:label ?ml .
  FILTER (lang(?ml) = "en") 
}

Try it!

Data of Douglas Adams[edit]

#added before 2016-10

PREFIX entity: <http://www.wikidata.org/entity/>
#partial results

SELECT ?propUrl ?propLabel ?valUrl ?valLabel ?picture
WHERE
{
	hint:Query hint:optimizer 'None' .
	{	BIND(entity:Q42 AS ?valUrl) . 
		BIND("N/A" AS ?propUrl ) .
		BIND("identity"@en AS ?propLabel ) .
	}
	UNION 
	{	entity:Q42 ?propUrl ?valUrl .
		?property ?ref ?propUrl .
		?property a wikibase:Property .
		?property rdfs:label ?propLabel
	}
	
  	?valUrl rdfs:label ?valLabel
	FILTER (LANG(?valLabel) = 'en') .
	OPTIONAL{ ?valUrl wdt:P18 ?picture .}
	FILTER (lang(?propLabel) = 'en' )
}
ORDER BY ?propUrl ?valUrl
LIMIT 200

Try it!

Samples with coordinates to illustrate maps[edit]

Locations of national parks[edit]

#added before 2016-10
#defaultView:Map

SELECT ?objectLabel ?objectDescription ?link ?coord
WHERE {
  ?object wdt:P31 wd:Q46169 ;
          wdt:P856 ?link ;
          wdt:P625 ?coord .

          SERVICE wikibase:label {
               bd:serviceParam wikibase:language "en,fr" .
          }
}

Try it!


Big cities, grouped into map layers by population[edit]

#defaultView:Map
SELECT DISTINCT ?city ?cityLabel (SAMPLE(?location) AS ?location) (MAX(?population) AS ?population) (SAMPLE(?layer) AS ?layer)
WHERE
{
  ?city wdt:P31/wdt:P279* wd:Q515;
        wdt:P625 ?location;
        wdt:P1082 ?population.
  FILTER(?population >= 500000).
  BIND(
    IF(?population < 1000000, "<1M",
    IF(?population < 2000000, "1M-2M",
    IF(?population < 5000000, "2M-5M",
    IF(?population < 10000000, "5M-10M",
    IF(?population < 20000000, "10M-20M",
    ">20M")))))
    AS ?layer).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?city ?cityLabel

Try it!

Places with free wifi[edit]

#added before 2016-10

# Places with free wi-fi
SELECT ?item ?itemLabel ?coord
WHERE
{
	?item wdt:P2848 wd:Q1543615 ;
	      wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Map of U1 subway stations in Berlin[edit]

#added before 2016-10
#defaultView:Map
SELECT ?stationLabel ?coord
WHERE {
	?station wdt:P81 wd:Q99691 ;
		 wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
}

Try it!

Locations of universities in Germany[edit]

#added before 2016-10
#defaultView:Map
SELECT ?universityLabel ?universityDescription ?website ?coord
WHERE {
	?university wdt:P31/wdt:P279* wd:Q3918 ;
		wdt:P17 wd:Q183 ;
		wdt:P625 ?coord .
	OPTIONAL {
		?university wdt:P856 ?website
	}
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en,de" .
	}
}

Try it!

Distribution of names of human settlements ending in "-ow" or "-itz" in Germany[edit]

#added before 2016-10
 #defaultView:Map
SELECT ?item ?itemLabel ?coord
WHERE 
{
	?item wdt:P31/wdt:P279* wd:Q486972;
    	      wdt:P17 wd:Q183;
    	      rdfs:label ?itemLabel;
    	      wdt:P625 ?coord;
    	 FILTER (lang(?itemLabel) = "de") . 
    	 FILTER regex (?itemLabel, "(ow|itz)$").
}

Try it!

Locations of power stations[edit]

#added before 2016-10
#defaultView:Map
SELECT DISTINCT ?objectLabel ?descriptionLabel ?coord
WHERE
{
  ?object wdt:P31/wdt:P279* wd:Q159719 .
  ?object schema:description ?description.
  ?object wdt:P625 ?coord.
       SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
      } .

}

Try it!

Locations of stone arch bridges[edit]

#added before 2016-10
#defaultView:Map
SELECT ?label ?coord ?place ?image
WHERE
{
	?subj wdt:P31 wd:Q14276458 .
	?subj wdt:P186 wd:Q22731 .
	?subj wdt:P625 ?coord .
	OPTIONAL { ?subj wdt:P18 ?image }
	?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Locations of aqueducts[edit]

#added before 2016-10
#defaultView:Map
SELECT ?label ?coord ?place
WHERE
{
   ?subj wdt:P31 wd:Q474 .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Locations of archaelogical sites[edit]

#added before 2016-10
#defaultView:Map
SELECT ?label ?coord ?place
WHERE
{
   ?subj wdt:P31 wd:Q839954 .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Locations of castles that are also archaeological sites[edit]

#added before 2016-10
#defaultView:Map
SELECT ?label ?coord ?subj 
WHERE
{
   ?subj wdt:P31 wd:Q839954 .
   ?subj wdt:P31 wd:Q23413 .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Locations of battles[edit]

#added before 2016-10
#defaultView:Map
SELECT ?label ?coord ?subj ?year
WHERE
{
	?subj wdt:P31 wd:Q178561 .
	?subj wdt:P625 ?coord .
	OPTIONAL {?subj wdt:P580 ?d1}
	OPTIONAL {?subj wdt:P585 ?d2}
  	OPTIONAL {?subj wdt:P582 ?d3}
	BIND(IF(!BOUND(?d1),(IF(!BOUND(?d2),?d3,?d2)),?d1) as ?date)
	BIND(YEAR(?date) as ?year)
	?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

All museums (including subclass of museum) in Washington, D.C. with coordinates[edit]

#added before 2016-10
#defaultView:Map
SELECT DISTINCT ?item ?name ?coord ?lat ?lon
WHERE {
   ?item wdt:P131* wd:Q61 .
   ?item wdt:P31/wdt:P279* wd:Q33506 .
   ?item wdt:P625 ?coord .
   ?item p:P625 ?coordinate .
   ?coordinate psv:P625 ?coordinate_node .
   ?coordinate_node wikibase:geoLatitude ?lat .
   ?coordinate_node wikibase:geoLongitude ?lon .
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
    ?item rdfs:label ?name
   }
}
ORDER BY ASC (?name)

Try it!

All ski resorts with coordinates[edit]

#added before 2016-10
#defaultView:Map
SELECT DISTINCT ?item ?name ?coord ?lat ?lon
WHERE
{
   ?item wdt:P31 wd:Q130003 .
   ?item wdt:P625 ?coord .
   ?item p:P625 ?coordinate .
   ?coordinate psv:P625 ?coordinate_node .
   ?coordinate_node wikibase:geoLatitude ?lat .
   ?coordinate_node wikibase:geoLongitude ?lon .
   SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
    ?item rdfs:label ?name
   }
}
ORDER BY ASC (?name)

Try it!

Lighthouses in Norway[edit]

#added before 2016-10
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?coor ?image
WHERE
{
	?item wdt:P31 wd:Q39715 . 
	?item wdt:P17 wd:Q20 .
	OPTIONAL { ?item wdt:P625 ?coor }
	OPTIONAL { ?item wdt:P18 ?image }  
	SERVICE wikibase:label { bd:serviceParam wikibase:language "nb,nn,en,fi"  }  
}
ORDER BY ?itemLabel

Try it!

Listeria[edit]

Samples suitable for Listeria. Generally only include ?item as output. Listeria will add more information from that item. Additional variables from the query could also be used in the lists.

Women born in Wales without an article in Welsh for Listeria[edit]

#added before 2016-10
 #sample from cywiki:Wicipedia:Merched_a_anwyd_yng_Nghymru
SELECT ?item
WHERE
{
	# gender = female
  	?item wdt:P21 wd:Q6581072 . 

  	# place of birth = Wales (Q25)
  	{ ?item wdt:P19 wd:Q25 }
	# OR place of birth within Wales. This relies on places using P131 with Q25 ("Wales") as value (or with a value that has Q25 in P131)
	UNION  { ?item wdt:P19 ?pob . ?pob wdt:P131* wd:Q25 } 

	# look for articles (sitelinks) in Welsh ("cy")
  	OPTIONAL { ?sitelink schema:about ?item . ?sitelink schema:inLanguage "cy" } 
	# but select items with no such article
	FILTER (!BOUND(?sitelink))

	# humans only
  	?item wdt:P31 wd:Q5 . 
}
#Listeria can only handle up to 5000
LIMIT 1000

Try it!

People born in Occitania for Listeria[edit]

#added before 2016-10
 #Definition for Occitania (Q104285) is the one defined by P527 on item Q104285
SELECT ?item ?yob ?yod 
WHERE 
{
	# items with property place of birth
	?item wdt:P19 ?pob .
	#place of birth must be using P131 with one of the "?parts" (or -- note the "*" -- a value that uses one of the parts in P131, etc.) 
	?pob wdt:P131* ?parts .

	# ?parts are those listed on item Q104285 with property P527
	wd:Q104285 wdt:P527 ?parts .  

	# humans only
  	?item wdt:P31 wd:Q5 . 

	#for display in the list, extract yob/yod. Could also be done by using P569 and P570 in "columns=" of Listeria's template
	OPTIONAL { ?item wdt:P569 ?dob . BIND(YEAR(?dob) as ?yob) }
	OPTIONAL { ?item wdt:P570 ?dod . BIND(YEAR(?dod) as ?yod) }
}
#LIMIT to 2000 as Listeria can only handle up to 5000
LIMIT 2000

Try it!

People born in Scotland for Listeria (1)[edit]

#added before 2016-10
 
SELECT ?item ?dob
WHERE
{
  	# place of birth = Scotland (Q22)
  	{ ?item wdt:P19 wd:Q22 }
	# OR place of birth within Scotland.
	UNION  { ?item wdt:P19 ?pob . ?pob wdt:P131* wd:Q22 }

	# humans only
  	?item wdt:P31 wd:Q5 . 

	# get DOB for ordering.
	OPTIONAL { ?item wdt:P569 ?dob  }
}
#Order by date of birth, avoid overriding this in the template with sort=
ORDER BY ?dob
#Listeria can only handle up to 5000
LIMIT 4000
#start at the first item
OFFSET 0

Try it!

People born in Scotland for Listeria (2)[edit]

#added before 2016-10
 #same as (1), but but skipping the 4000 items in that list
SELECT ?item ?dob
WHERE
{
  	{ ?item wdt:P19 wd:Q22 }
	UNION  { ?item wdt:P19 ?pob . ?pob wdt:P131* wd:Q22 }
  	?item wdt:P31 wd:Q5 . 
	OPTIONAL { ?item wdt:P569 ?dob  }
}
ORDER BY ?dob
LIMIT 4000
#start at the 4001th item
OFFSET 4000

Try it!

Entertainment[edit]

Rock bands that start with "M"[edit]

SELECT DISTINCT ?band ?bandLabel
WHERE
{
	?band  wdt:P31 wd:Q5741069 . 
        ?band rdfs:label ?bandLabel .
	FILTER(STRSTARTS(?bandLabel, 'M')) .
}

Try it!

Winner of the Academy Awards by Award and Time[edit]

SELECT DISTINCT ?item ?itemLabel ?awardLabel ?time
{
    ?item wdt:P106/wdt:P279* wd:Q3455803 ; # Items with the Occupation(P106) of Director(Q3455803) or a subclass(P279)
          p:P166 ?awardStat .              # ... with an awarded(P166) statement
    ?awardStat pq:P805 ?award ;            # Get the award (which is "subject of" XXth Academy Awards)
               ps:P166 wd:Q103360 .        # ... that has the value Academy Award for Best Director(Q103360)
    ?award wdt:P585 ?time .                # the "point of time" of the Academy Award
    SERVICE wikibase:label {               # ... include the labels
        bd:serviceParam wikibase:language "en"
    }
}
ORDER BY DESC(?time)

Try it!

Academy award data[edit]

#added before 2016-10
SELECT ?human ?humanLabel ?awardEditionLabel ?awardLabel ?awardWork ?awardWorkLabel ?director ?directorLabel ?time 
WHERE 
{
	{
		SELECT (SAMPLE(?human) AS ?human) ?award ?awardWork (SAMPLE(?director) AS ?director) (SAMPLE(?awardEdition) AS ?awardEdition) (SAMPLE(?time) AS ?time) WHERE {
			?award wdt:P31 wd:Q19020 .			# All items that are instance of(P31) of Academy awards (Q19020)
			{
				?human p:P166 ?awardStat .              # Humans with an awarded(P166) statement
				?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
				?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
				?awardStat pq:P1686 ?awardWork . # The work they have been awarded for
				?human wdt:P31 wd:Q5 . 				# Humans
			} UNION {
				?awardWork wdt:P31 wd:Q11424 . # Films
				?awardWork p:P166 ?awardStat . # ... with an awarded(P166) statement
				?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
				?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
			}
			OPTIONAL {
				?awardEdition wdt:P585 ?time . # the "point of time" of the Academy Award
				?awardWork wdt:P57 ?director .
			}
		}
		GROUP BY ?awardWork ?award # We only want every movie once for a category (a 'random' person is selected)
	}

	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "en" .
	}
}
ORDER BY DESC(?time)

Try it!

People that received both Academy Award and Nobel Prize[edit]

The following query uses these:

SELECT DISTINCT ?personLabel WHERE {
  ?person wdt:P166/wdt:P279* wd:Q7191 .
  ?person wdt:P166/wdt:P279* wd:Q19020 .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Try it!

Number of handed out academy awards per award type[edit]

#added before 2016-10

SELECT ?awardCount ?award ?awardLabel WHERE {
	{
		SELECT (COUNT(?award) AS ?awardCount) ?award
		WHERE 
		{
			{
				SELECT (SAMPLE(?human) AS ?human) ?award ?awardWork (SAMPLE(?director) AS ?director) (SAMPLE(?awardEdition) AS ?awardEdition) (SAMPLE(?time) AS ?time) WHERE {
					?award wdt:P31 wd:Q19020 .			# All items that are instance of(P31) of Academy awards (Q19020)
					{
						?human p:P166 ?awardStat .              # Humans with an awarded(P166) statement
						?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
						?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
						?awardStat pq:P1686 ?awardWork . # The work they have been awarded for
						?human wdt:P31 wd:Q5 . 				# Humans
					} UNION {
						?awardWork wdt:P31 wd:Q11424 . # Films
						?awardWork p:P166 ?awardStat . # ... with an awarded(P166) statement
						?awardStat ps:P166 ?award .     	 # ... that has any of the values of ?award
						?awardStat pq:P805 ?awardEdition . # Get the award edition (which is "subject of" XXth Academy Awards)
					}
					OPTIONAL {
						?awardEdition wdt:P585 ?time . # the "point of time" of the Academy Award
						?awardWork wdt:P57 ?director .
					}
				}
				GROUP BY ?awardWork ?award # We only want every movie once for a category (a 'random' person is selected)
			}
		} GROUP BY ?award
		ORDER BY ASC(?awardCount)
	}
	SERVICE wikibase:label {            # ... include the labels
		bd:serviceParam wikibase:language "en" .
	}
}

Try it!

Film directors ranked by number of sitelinks multiplied by their number of films[edit]

#added before 2016-10

SELECT ?director ?director_label (count(distinct ?film) as ?films) (count(distinct ?sitelink) as ?sitelinks) ((?films * ?sitelinks) as ?rank)
WHERE
{
	?director wdt:P106 wd:Q2526255 .  				# has "film director" as occupation
	?film wdt:P57 ?director . 	 					# get all films directed by the director
    ?sitelink schema:about ?director .				# get all the sitelinks about the director

	OPTIONAL {?director rdfs:label ?director_label  # get the label of the director (if it exists)
              FILTER (lang(?director_label) = "en") # filter for only English labels
	} 	
}

GROUP BY ?director ?director_label
ORDER BY DESC(?rank)
LIMIT 100

Try it!

The Simpsons television series episodes list by season[edit]

#added before 2016-10
SELECT ?show ?showLabel  ?season ?seasonNumber ?episode ?episodeLabel
WHERE
{
	BIND(wd:Q886 as ?show) .
	?season wdt:P361 ?show .
	?episode wdt:P361 ?season .
	?season p:P179 [
	        pq:P1545 ?seasonNumber] .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!

Pokemon![edit]

#added before 2016-10

# Gotta catch 'em all
SELECT ?pokemon ?pokemonLabel ?pokedexNumber
WHERE
{
    ?pokemon wdt:P31/wdt:P279* wd:Q3966183.
    ?pokemon wdt:P1112 ?pokedexNumber
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY (?pokedexNumber)

Try it!


Law & Order episodes[edit]

# All Law & Order episodes on Wikidata.
# According to enwp, “[a] total of 456 original episodes… aired before cancellation” (https://en.wikipedia.org/wiki/List_of_Law_%26_Order_episodes).
# As of this writing, the query returns 451 results, so some episodes are missing (either without item or lacking the necessary statements to match this query).

SELECT (SAMPLE(?seasonNumber) AS ?seasonNumber) (SAMPLE(?episodeNumber) AS ?episodeNumber) (SAMPLE(?title) AS ?title) (MIN(?pubDate) AS ?pubDate) ?episode
{
  # All episodes should be instance of episode with series Law & Order.
  ?episode wdt:P31 wd:Q21191270;
           wdt:P179 wd:Q321423.
  # Many of them also have the season as series, so we can get episode and season number from qualifiers there.
  OPTIONAL {
    ?episode p:P179 [
      # the season also has series Law & Order
      ps:P179/p:P179 [
        ps:P179 wd:Q321423;
                pq:P1545 ?seasonNumber
      ] ;
      pq:P1545 ?episodeNumber
    ]
  }
  OPTIONAL { ?episode wdt:P1476 ?title. }
  OPTIONAL { ?episode wdt:P577 ?pubDate. }
}
GROUP BY ?episode # make sure we return each episode only once – a few have multiple publication dates, for example
ORDER BY IF(BOUND(?seasonNumber), xsd:integer(?seasonNumber), 1000) xsd:integer(?episodeNumber) ?title

Try it!

Main subjects of West Wing episodes[edit]

#added before 2016-10

SELECT DISTINCT ?subject ?subjectLabel
WHERE
{
  ?episode wdt:P31/wdt:P279* wd:Q1983062.
  ?episode wdt:P179 wd:Q3577037.
  ?episode wdt:P921 ?subject.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Movies with Bud Spencer[edit]

#added before 2016-10
SELECT ?item ?itemLabel ?_image
WHERE
{
  ?item wdt:P161 wd:Q221074.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  OPTIONAL { ?item wdt:P18 ?_image. }
}

Try it!

Fictional subjects of the Marvel Universe[edit]

#added before 2016-10

SELECT *
WHERE
{
	?u rdfs:label ?ul .
	FILTER (lang(?ul) = "en") 
	?m rdfs:label ?ml .
	FILTER (lang(?ml) = "en") 
	?p wdt:P1080 ?u.
	?p wdt:P31 ?m .
	?p wdt:P1080 wd:Q931597 .
	?p rdfs:label ?pl . 
	FILTER (lang(?pl) = "en") 
}

Try it!

Contemporary Indian actresses[edit]

#added 2016-10-0 (1998 results)
SELECT ?item ?itemLabel ?itemDescription ?img ?dob ?sl
WHERE
{
	?item wdt:P106 wd:Q33999 .
	?item wdt:P27 wd:Q668 .
	?item wdt:P21 wd:Q6581072 .
	OPTIONAL { ?item wdt:P570 ?d } FILTER(!BOUND(?d))  
	?item wdt:P31 wd:Q5 .
	OPTIONAL { ?item wdt:P18 ?img }
	OPTIONAL { ?item wdt:P569 ?dob }  
	OPTIONAL { ?item wikibase:sitelinks ?sl }  
  	SERVICE wikibase:label { bd:serviceParam wikibase:language "en"}
}

Try it!

Geography[edit]

Continents[edit]

Continents[edit]

#added before 2016-10

SELECT ?continent ?continentLabel
WHERE
{
  ?continent wdt:P31 wd:Q5107.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY xsd:integer(SUBSTR(STR(?continent),STRLEN("http://www.wikidata.org/entity/Q")+1))

Try it!

Some other continents[edit]

#added before 2016-10

SELECT ?continentLabel
WHERE
{
  { # subquery for optimization so the label service doesn’t have to do as much work (228?ms vs 20731?ms)
    SELECT DISTINCT ?continent
    WHERE
    {
      [] wdt:P30 ?continent.
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY xsd:integer(SUBSTR(STR(?continent),STRLEN("http://www.wikidata.org/entity/Q")+1))

Try it!

Places with continent Antarctica more than 3000?km north of south pole[edit]

#added before 2016-10

#defaultView:Map
SELECT ?place ?placeLabel ?location WHERE {
  wd:Q933 wdt:P625 ?southPole.                         # coordinates of south pole
  ?place wdt:P30 wd:Q51;                               # continent: antarctica
         wdt:P625 ?location.
  FILTER(geof:distance(?location, ?southPole) > 3000). # over 3000?km away from south pole
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Countries[edit]

List of present-day countries and capital(s)[edit]

#added before 2016-10
SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel
WHERE
{
  ?country wdt:P31 wd:Q3624078 .
  FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
  OPTIONAL { ?country wdt:P36 ?capital } .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?countryLabel

Try it!

Largest cities per country[edit]

#added before 2016-10

#Largest cities per country
SELECT DISTINCT ?city ?cityLabel ?population ?country ?countryLabel ?loc WHERE {
	{
		SELECT (MAX(?population) AS ?population) ?country WHERE {
			?city wdt:P31/wdt:P279* wd:Q515 .
			?city wdt:P1082 ?population .
			?city wdt:P17 ?country .
		}
		GROUP BY ?country
		ORDER BY DESC(?population)
	}
	?city wdt:P31/wdt:P279* wd:Q515 .
	?city wdt:P1082 ?population .
	?city wdt:P17 ?country .
	?city wdt:P625 ?loc .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}

Try it!

Wikidata people per million inhabitants for all EU countries[edit]

#added before 2016-10

#Interesting maintenance query that shows the relative prominence of a country's current (living) population on Wikidata. The query tends to time out when using all countries at once, but it might be possible to get the figures for each individual country by using uncommenting the line as indicated below
SELECT
	?country ?countryLabel
	?wikiPersons
	?population
	(ROUND(?wikiPersons/?population*1000000) AS ?wikiPersonsPerM)
WHERE
{
	{ SELECT ?country (count(*) as ?wikiPersons) WHERE {
		{SELECT DISTINCT ?person ?country WHERE {
			?country wdt:P31 wd:Q185441 .
			# BIND( wd:Q30 AS ?country ) # use instead of previous line to check individual countries
			?person wdt:P31 wd:Q5 .
			?person wdt:P27 ?country .
			FILTER NOT EXISTS{ ?person wdt:P570 ?date } # only count living people
		} }
	} GROUP BY ?country  }
	?country wdt:P1082 ?population
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?wikiPersonsPerM)

Try it!

Papers about wikidata[edit]

#added before 2016-10

#papers about Wikidata
SELECT ?item ?itemLabel
WHERE
{
  ?item (wdt:P31/wdt:P279*) wd:Q191067.
  ?item wdt:P921 wd:Q2013.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Countries sorted by population[edit]

# defaultView:BubbleChart
SELECT DISTINCT ?countryLabel ?population
{
  ?country wdt:P31 wd:Q6256 ;
           wdt:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?population ?countryLabel
ORDER BY DESC(?population)

Try it!

Country populations together with total city populations[edit]

Lists for each country the population and the total of the populations of all cities of this country. If data were complete and populations were measured at the same time for each country and the respective cities then the ratio would be 1.

SELECT ?country ?countryLabel ?population ?totalCityPopulation (?population / ?totalCityPopulation AS ?ratio) {
  ?country wdt:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  {
    SELECT ?country (SUM(?cityPopulation) AS ?totalCityPopulation) WHERE {
      ?city wdt:P31 wd:Q515 .
      ?city wdt:P17 ?country .
      ?city wdt:P1082 ?cityPopulation .
    } GROUP BY ?country
  }
} ORDER BY ?ratio

Try it!

Cities[edit]

Former capitals[edit]

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?country ?countryLabel ?capital ?capitalLabel ?coordinates ?ended
WHERE
{
  ?country p:P36 ?stat.
  ?stat ps:P36 ?capital.
  ?capital wdt:P625 ?coordinates.
  OPTIONAL {
    ?country wdt:P582|wdt:P576 ?ended.
  }
  OPTIONAL {
    ?capital wdt:P582|wdt:P576 ?ended.
  }
  OPTIONAL {
    ?stat pq:P582 ?ended.
  }
  FILTER(BOUND(?ended)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Largest cities of the world[edit]

#added before 2016-10
 #defaultView:BubbleChart
SELECT DISTINCT ?cityLabel ?population ?gps
WHERE 
{
  ?city wdt:P31/wdt:P279* wd:Q515 .
  ?city wdt:P1082 ?population .
  ?city wdt:P625 ?gps .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}
ORDER BY DESC(?population) LIMIT 100

Try it!

Cities as big as Antwerp give or take 1000[edit]

The following query uses these:

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?city ?cityLabel ?populatie2 ?coor WHERE {
  wd:Q12892 wdt:P1082 ?populatie .
  ?city wdt:P1082 ?populatie2 ;
        wdt:P625 ?coor .
  FILTER (abs(?populatie - ?populatie2) < 1000)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl" }
}

Try it!

Cities as big as Eindhoven give or take 1000[edit]

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?city ?cityLabel ?location ?populatie2 WHERE {
  wd:Q9832 wdt:P1082 ?populatie .
  ?city wdt:P1082 ?populatie2 ;
        wdt:P625 ?location .
  FILTER (abs(?populatie - ?populatie2) < 1000)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl" }
}

Try it!

Where in the world is Antwerp[edit]

The following query uses these:

#added before 2016-10
 
#defaultView:Map
SELECT DISTINCT ?settlement ?name ?coor
WHERE
{
   
   ?subclass_settlement wdt:P279+ wd:Q486972 .
   ?settlement wdt:P31 ?subclass_settlement ;
               wdt:P625 ?coor ;
                rdfs:label ?name .
   FILTER regex(?name, "Antwerp", "i") 

}

Try it!

Destinations from Antwerp International airport[edit]

The following query uses these:

#added before 2016-10

#defaultView:Map
SELECT ?connectsairport ?connectsairportLabel ?place_served ?place_servedLabel ?coor
WHERE
{
  VALUES ?airport { wd:Q17480 } # Antwerp international airport  wd:Q17480
  ?airport wdt:P81 ?connectsairport ;
           wdt:P625 ?base_airport_coor .
  ?connectsairport wdt:P931 ?place_served ;
                   wdt:P625 ?coor .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Cities connected by the European route E40[edit]

The following query uses these:

#added before 2016-10
 
#defaultView:Map
SELECT ?city ?cityLabel ?coordinates
WHERE
{
   VALUES ?highway {wd:Q327162 } 
   ?highway wdt:P2789 ?city .
    ?city wdt:P625 ?coordinates .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Cities connected by the Trans-Mongolian and Trans-Siberian Railway[edit]

The following query uses these:

#added before 2016-10
 
#defaultView:Map
SELECT ?city ?cityLabel ?coordinates
WHERE
{
   VALUES ?highway { wd:Q559037 wd:Q58767 } 
   ?highway wdt:P2789 ?city .
    ?city wdt:P625 ?coordinates .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Cities connected to Paramaribo (Suriname) by main roads[edit]

The following query uses these:

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?connection ?connectionLabel ?connectedWith ?connectedWithLabel ?coor
WHERE
{
  VALUES ?city {wd:Q3001} # wd:Q3001 = Paramaribo}
  ?connection wdt:P2789+ ?city ;
              wdt:P2789+ ?connectedWith .
  ?connectedWith wdt:P625 ?coor .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  }

Try it!

Names of 100 cities with a population larger than 1000000 in the native languages of their countries[edit]

The following query uses these:

#added before 2016-10

# Show the names of 100 cities with a population larger than 1000000 in the native languages of their countries
SELECT ?city ?cityLabel ?country ?countryLabel ?lang ?langLabel ?langCode ?population
WHERE
{
  ?city wdt:P1082 ?population .
  
  FILTER(?population>1000000)
  
  ?city wdt:P31 wd:Q515;
        wdt:P17 ?country;
        rdfs:label ?cityLabel .
  ?country wdt:P37 ?lang;
           rdfs:label ?countryLabel .
  ?lang wdt:P424 ?langCode;
        rdfs:label ?langLabel .
  
  FILTER(lang(?cityLabel)=?langCode)
  FILTER(lang(?countryLabel)=?langCode)
  FILTER(lang(?langLabel)=?langCode)
} LIMIT 100

Try it!

Rivers[edit]

Longest rivers[edit]

The following query uses these:

#added before 2016-10
 
#defaultView:BubbleChart
SELECT ?item ?itemLabel ?length ?pic ?location
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q4022 .
  ?item wdt:P2043 ?length .
  ?item wdt:P18 ?pic .
  ?item wdt:P625 ?location
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
} ORDER BY DESC(?length) ?itemLabel
LIMIT 50

Try it!

Longest river of each continent[edit]

The following query uses these:

#added before 2016-10

SELECT ?continent ?river ?continentLabel ?riverLabel
WHERE
{
  {
    SELECT ?continent (MAX(?length) AS ?length)
    WHERE
    {
      ?river wdt:P31/wdt:P279* wd:Q355304;
             wdt:P2043 ?length;
             wdt:P30 ?continent.
    }
    GROUP BY ?continent
  }
  ?river wdt:P31/wdt:P279* wd:Q355304;
         wdt:P2043 ?length;
         wdt:P30 ?continent.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?continentLabel

Try it!

Body of water with the most watercourses ending in it[edit]

#added before 2016-10

# Bodies of water that most watercourses end in (transitive).
# For example, over 4000 watercourses eventually flow into the Ob,
# and since the Ob flows into the Kara Sea, the Kara Sea has over 4000 results as well.
SELECT ?mouth (COUNT(?watercourse) AS ?count)
WHERE
{
  ?watercourse wdt:P403+ ?mouth.
}
GROUP BY ?mouth
ORDER BY DESC(?count)
LIMIT 10

Try it!

Rivers in Antarctica[edit]

#added before 2016-10

SELECT ?river ?riverLabel ?location
WHERE
{
  ?river wdt:P31/wdt:P279* wd:Q355304; # watercourse; includes a few creeks – use wd:Q4022 for rivers only
         wdt:P30 wd:Q51.
  OPTIONAL { ?river wdt:P625 ?location. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Mountains[edit]

Mountains, with coordinates, not located on Earth[edit]

SELECT DISTINCT ?item ?name ?coord ?lat ?lon ?globe
{
   ?item wdt:P31 wd:Q8502 ;
         p:P625 [
           psv:P625 [
             wikibase:geoLatitude ?lat ;
             wikibase:geoLongitude ?lon ;
             wikibase:geoGlobe ?globe ;
           ] ;
           ps:P625 ?coord
         ]
  FILTER ( ?globe != wd:Q2 )
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
    ?item rdfs:label ?name
   }
}
ORDER BY ASC (?name)

Try it!

Highest mountains in the universe[edit]

#added before 2016-10

#Mountains over 8000 elevation
SELECT ?subj ?label ?coord ?elev 
WHERE
{
	?subj wdt:P2044 ?elev	filter(?elev > 8000) .
	?subj wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,zh" . ?subj rdfs:label ?label } 
}

Try it!

Mountains over 8000 elevation[edit]

elevation above sea level (P2044)

#added before 2016-10
 
SELECT ?subj ?label ?coord ?elev 
WHERE
{
	?subj wdt:P2044 ?elev	filter(?elev > 8000) .
	?subj wdt:P625 ?coord .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,zh" . ?subj rdfs:label ?label } 
}

Try it!

Italian mountains higher than 4000 m[edit]

#added before 2016-10
 
#defaultView:ImageGrid
SELECT ?subj ?label ?coord ?elev ?picture
WHERE
{
	?subj wdt:P2044 ?elev	filter(?elev > 4000) .
	?subj wdt:P625 ?coord .
    ?subj wdt:P17 wd:Q38 .
  	?subj wdt:P18 ?picture .

	SERVICE wikibase:label { bd:serviceParam wikibase:language "it" . ?subj rdfs:label ?label } 
}

Try it!

Metro stations in Paris[edit]

SELECT ?item ?itemLabel ?adjacent ?adjacentL ?coords
{
  ?item wdt:P31/wdt:P279* wd:Q928830 ;
        wdt:P81 wd:Q13224 ;
        wdt:P625 ?coords .
  OPTIONAL {
    ?item p:P197 [ ps:P197 ?adjacent ; pq:P560 wd:Q585752 ] .
    ?adjacent rdfs:label ?adjacentL filter (lang(?adjacentL) = "en")
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
} ORDER BY ?itemLabel

Try it!

Map of Broadway venues[edit]

#added before 2016-10

#defaultView:Map
# Venues in Broadway
SELECT DISTINCT ?venue ?venueLabel ?coords {
  	?venue wdt:P1217 ?IDBDB .
    wd:Q235065 wdt:P625 ?broadWayLoc .

    SERVICE wikibase:around {
      ?venue wdt:P625 ?coords .
      bd:serviceParam wikibase:center ?broadWayLoc . 
      bd:serviceParam wikibase:radius "1.5" . 
    }

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Try it!

How many states this US state borders[edit]

#added before 2016-10
SELECT ?state ?stateLabel ?borders 
WHERE 
{
	{
		SELECT ?state (COUNT(?otherState) as ?borders) 
		WHERE
		{
		?state wdt:P31 wd:Q35657 .
		?otherState wdt:P47 ?state .
		?otherState wdt:P31 wd:Q35657 .
		} 
		GROUP BY ?state
	}
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}         
ORDER BY DESC(?borders)

Try it!

Places that are below 10 meters above sea level[edit]


#added before 2016-10

#defaultView:Map
SELECT ?p ?location ?el ?image
WHERE
{ 
  ?p p:P2044/psv:P2044 ?pel.
  ?pel wikibase:quantityAmount ?el.
  ?pel wikibase:quantityUnit ?unit.
  bind(0.01 as ?km).
  filter( (?el < ?km*1000 && ?unit = wd:Q11573) ||
         (?el < ?km*3281 && ?unit = wd:Q3710)
       || (?el < ?km && ?unit = wd:Q828224) ). 
  ?p wdt:P625 ?location.
  optional { ?p wdt:P18 ?image }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Globes used to represent coordinates[edit]

#added before 2016-10
 SELECT (count(?v) as ?c) ?globe 
WHERE
{
	?v wikibase:geoGlobe ?globe
}
GROUP BY ?globe 
ORDER BY DESC(?c)

Try it!

Places within 1km of the Empire State Building[edit]


#added before 2016-10
 SELECT ?place ?placeLabel ?location ?instanceLabel
WHERE
{
  wd:Q9188 wdt:P625 ?loc . 
  SERVICE wikibase:around { 
      ?place wdt:P625 ?location . 
      bd:serviceParam wikibase:center ?loc . 
      bd:serviceParam wikibase:radius "1" . 
  } 
  OPTIONAL {  	?place wdt:P31 ?instance  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
  BIND(geof:distance(?loc, ?location) as ?dist) 
} ORDER BY ?dist

Try it!

Select French municipalities by INSEE code (select by identifier)[edit]

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX q: <http://www.wikidata.org/prop/qualifier/>
PREFIX v: <http://www.wikidata.org/prop/statement/>#added before 2016-10
SELECT ?entityLabel ?inseeCode ?entity
WHERE 
{
	?entity wdt:P374 ?inseeCode .
	FILTER (
		 ?inseeCode in ("75056", "69123", "13055")
	)
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Emergency numbers by population using them[edit]

#added before 2016-10

#Lists emergency numbers and the total amount of people which can use them
#defaultView:BubbleChart
SELECT ?emergencyNumber ?emergencyNumberLabel ?tel ?population ?countries
WHERE
{
 ?emergencyNumber wdt:P31 wd:Q694554 .
  OPTIONAL{SELECT ?emergencyNumber (COUNT(?state) as ?countries) (SUM(?pop) as ?population) WHERE {
  	?state wdt:P2852 ?emergencyNumber .
  	OPTIONAL{?state wdt:P1082 ?pop} .
  	?state wdt:P31/wdt:P279* wd:Q6256
  } GROUP BY ?emergencyNumber } .
  OPTIONAL{?emergencyNumber wdt:P1329 ?tel }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?population)

Try it!

German states, ordered by the number of company headquarters per million inhabitants[edit]

#added before 2016-10

# German states, ordered by the number of company headquarters per million inhabitants
# Replace wd:Q1221156 (state of Germany) by anything else you care about, e.g., wd:Q6256 (country)
# Nested queries for correctness (don't count companies twice) and performance (aggregate before adding more data)
# Limits: states without population missing; company data in Wikidata is always incomplete
# Note: This query shows some not-so-easy nesting of DISTINCT (don't count any company twice) and aggregate, in combination with arithmetic output evaluation functions. It is a hard query that may time out if modified.
SELECT
	?state ?stateLabel
	?companies
	?population
	(?companies/?population*1000000 AS ?companiesPerM)
WHERE
{
	{ SELECT ?state (count(*) as ?companies) WHERE {
		{SELECT DISTINCT ?company ?state WHERE {
			?state wdt:P31 wd:Q1221156 .
			?company wdt:P31/wdt:P279* wd:Q4830453 .
			?company wdt:P159/wdt:P131* ?state .
			FILTER NOT EXISTS{ ?company wdt:P576 ?date } # don't count dissolved companies
		} }
	} GROUP BY ?state  }
    ?state wdt:P1082 ?population
	SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
}
ORDER BY DESC(?companiesPerM)

Try it!

Popular names per birthplace[edit]

#added before 2016-10
 
#defaultView:BubbleChart
SELECT ?cid ?firstname (COUNT(*) AS ?count)
WHERE
{
  ?pid wdt:P19 wd:Q64.
  ?pid wdt:P735 ?cid.
  OPTIONAL {
    ?cid rdfs:label ?firstname 
    FILTER((LANG(?firstname)) = "en")
  }
}
GROUP BY ?cid ?firstname
ORDER BY DESC(?count) ?firstname
LIMIT 50

Try it!


Map of places mentioned in travel stories with text in French accessible online[edit]

#added before 2016-10

#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?ed ?edLabel ?auteurLabel (year(?dateCreation) as ?AnneeCreation) ?lieuLabel ?coord ?lien
WHERE
{
  ?item wdt:P136 wd:Q1164267 .    # genre :récit de voyage
  ?item  wdt:P31 wd:Q571 .        # nature : livre 
  OPTIONAL{
    ?item wdt:P50 ?auteur .       # [option] auteur
  }
  OPTIONAL{
    ?item wdt:P571 ?dateCreation. # [option] date de création               
  }
  
  ?item  wdt:P840 ?lieu .         # lieu de l'action
  MINUS {?item  wdt:P840 wd:Q933} # (bug du Pôle Sud)
  ?lieu wdt:P625 ?coord .         # coordonnées géographiques du lieu
  
  {
    ?item wdt:P953 ?lien .        # URL, texte intégral disponible sur 
    ?item wdt:P364 wd:Q150        # langue originale : français
  }UNION{
    ?ed wdt:P629 ?item .          # édition du livre
    ?ed wdt:P953 ?lien .          # URL, texte intégral disponible sur  
    ?ed wdt:P407 wd:Q150          # langue de l'œuvre : français
  }

  SERVICE wikibase:label {        #BabelRainbow
    bd:serviceParam wikibase: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 ?dateCreation

Try it!

Things located where the equator meets the prime meridian[edit]

#added before 2016-10

SELECT ?place ?placeLabel ?location
WHERE
{
  wd:Q24041662 wdt:P625 ?loc00 . 
  SERVICE wikibase:around { 
    ?place wdt:P625 ?location . 
    bd:serviceParam wikibase:center ?loc00 . 
    bd:serviceParam wikibase:radius "0.001" . 
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .  }
}
ORDER BY ?placeLabel

Try it!

French communes with names ending in ac[edit]

#added before 2016-10

#defaultView:Map
SELECT ?item ?itemLabel ?coord
WHERE
{
	?item	wdt:P31/wdt:P279* wd:Q484170;
				wdt:P17 wd:Q142;
				rdfs:label ?itemLabel;
				wdt:P625 ?coord;
	FILTER (lang(?itemLabel) = "fr"). 
	FILTER regex (?itemLabel, "ac$").
	FILTER not exists { ?item wdt:P131 wd:Q33788 } # excluding Koumac, New Caledonia...
}

Try it!

Buildings in more than one country[edit]

#added before 2016-10
SELECT ?item ?itemLabel ?count
WHERE
{
  {
    SELECT ?item (COUNT(DISTINCT ?country) AS ?count) WHERE {
      ?item wdt:P31/wdt:P279* wd:Q41176 .
      ?item wdt:P17 ?country .
      FILTER NOT EXISTS { ?country wdt:P576 ?end }
    }
    GROUP BY ?item
  }
  FILTER ( ?count > 1 )
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY DESC(?count) ?itemL

Try it!

Demography[edit]

Birthplaces of people named Antoine[edit]

#added before 2016-10

# Coordinates of the birth places of people named Antoine
#defaultView:Map
SELECT ?item ?itemLabel ?coord
WHERE
{
  ?item wdt:P735 wd:Q15235674.
  ?item wdt:P19 ?place.
  ?place wdt:P625 ?coord.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". }
}

Try it!

Average lifespan by occupation[edit]

#added before 2016-10

# Select the desired columns and get labels
SELECT ?occ ?occLabel ?avgAge ?avgBirthYear ?count
WHERE
{
  {
    # Group the people by their occupation and calculate age
    SELECT
    	?occ
        (count(?p) as ?count)
        (round(avg(?birthYear)) as ?avgBirthYear)
        (avg(?deathYear - ?birthYear) as ?avgAge)
    WHERE {
      {
        # Get people with occupation + birth/death dates; combine multiple birth/death dates using avg
        SELECT
        	?p
            ?occ
            (avg(year(?birth)) as ?birthYear)
            (avg(year(?death)) as ?deathYear)
        WHERE {
           ?p  wdt:P31 wd:Q5 ;
              wdt:P106 ?occ ;
              p:P569/psv:P569 [
                wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
                wikibase:timeValue ?birth ;
              ] ;
              p:P570/psv:P570 [
                wikibase:timePrecision "9"^^xsd:integer ; # precision of at least year
                wikibase:timeValue ?death ;
              ] .
        }
        GROUP BY ?p ?occ
      } 
    }
    GROUP BY ?occ
  }
  
  FILTER (?count > 300) # arbitrary number to weed out values with 'few' observations
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY ASC(?avgAge)

Try it!


Items with the most birth dates[edit]

SELECT ?person (COUNT(?date) AS ?dateC) {
  ?person wdt:P569 ?date
}
GROUP BY ?person
HAVING (?dateC > 2) 
ORDER BY DESC (?dateC)
LIMIT 100

Try it!

Things/people with most children[edit]

#added before 2016-10
SELECT ?parent ?parentLabel ?count
WHERE
{
  {
    SELECT ?parent (COUNT(?child) AS ?count)
    WHERE
    {
      ?parent wdt:P40 ?child.
    }
    GROUP BY ?parent
    ORDER BY DESC(?count)
    LIMIT 10
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?count)
LIMIT 10

Try it!

Population growth in Suriname from 1960 onward[edit]

#defaultView:LineChart
SELECT ?year ?population {
  wd:Q730 p:P1082 ?p .
  ?p pq:P585 ?year ;
     ps:P1082 ?population .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?year

Try it!

Politics[edit]

Gender balance of members of Irish parliament[edit]

#added before 2016-10
 SELECT ?genderlabel (COUNT(?genderlabel) as ?total)
WHERE
{
   ?subj wdt:P39 wd:Q654291  .
   ?subj wdt:P21 ?gender .
  
   ?gender rdfs:label ?genderlabel filter (lang(?genderlabel) = "en") .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}
GROUP BY ?genderlabel

Try it!

Assemblies by number of seats[edit]

#added before 2016-10

SELECT DISTINCT ?item ?title ?seats ?jurisdiction (YEAR(?inception) AS ?start) (YEAR(?dissolution) AS ?end)
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q1752346 .
  OPTIONAL { ?item wdt:P1342 ?seats . }
  OPTIONAL {
    ?item wdt:P1001 ?j .
    ?j rdfs:label ?jurisdiction filter (lang(?jurisdiction) = "en") .
  }
  OPTIONAL { ?item wdt:P571 ?inception . }
  OPTIONAL { ?item wdt:P576 ?dissolution . }
  OPTIONAL { ?item rdfs:label ?title filter (lang(?title) = "en") . }
} 
ORDER BY DESC(?seats) ?title

Try it!

List of countries by age of the head of government[edit]

#added by Jura1, rev. 2016-11-08
SELECT DISTINCT ?age ?country ?countryLabel ?hgovernment ?hgovernmentLabel
{
	?country wdt:P31 wd:Q3624078 . 
	FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
	?country p:P6 ?statement .     
	?statement ps:P6 ?hgovernment . 
	?country wdt:P6 ?hgovernment . 
	FILTER NOT EXISTS { ?statement pq:P582 ?x }  
	?hgovernment wdt:P569 ?dob . BIND(YEAR(now())-YEAR(?dob) as ?age)
	FILTER(?age>=65)
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?age)

Try it!

Number of ministers who are themselves children of a minister, per country[edit]

#added before 2016-10
SELECT ?cc (COUNT(DISTINCT ?child) AS ?number)
WHERE
{
  ?child wdt:P31 wd:Q5 . # Looking for real humans and not fictional ones
  ?child wdt:P39/wdt:P279* wd:Q83307 . 
  {  
     ?child wdt:P22 ?parent . 
     ?parent wdt:P39/wdt:P279* wd:Q83307 . 
  } UNION { 
     ?child wdt:P25 ?parent . 
     ?parent wdt:P39/wdt:P279* wd:Q83307 .
  }
  
  ?child wdt:P27 ?country .
  ?country wdt:P901 ?cc .
  
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  } 
}
GROUP BY ?cc 
ORDER BY DESC(?number)

Try it!

Members of the French National Assembly born out of France[edit]

#added before 2016-10

SELECT DISTINCT ?item ?itemLabel ?placeLabel ?countryLabel
WHERE
{
  ?item wdt:P39 wd:Q3044918 .
  ?item wdt:P19 ?place .
  ?place wdt:P17 ?country .
  FILTER NOT EXISTS { ?place wdt:P17 wd:Q142 . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" . }
} 
ORDER BY ?countryLabel ?itemLabel

Try it!

List of parliament buildings with pictures by country[edit]

#added before 2016-10

#defaultView:ImageGrid
SELECT ?building ?buildingLabel ?country ?countryLabel ?picture
WHERE
{
	?building wdt:P31 wd:Q7138926 .
	?building wdt:P18 ?picture .
	OPTIONAL { ?building wdt:P17 ?country } .   #if available
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}
ORDER BY ?countryLabel
LIMIT 188

Try it!

Number of jurisdictions by driving side[edit]

#added before 2016-10
SELECT ?sideLabel (COUNT(?jurisdiction) AS ?count)
WHERE
{
  ?jurisdiction wdt:P1622 ?side.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?sideLabel
ORDER BY ?sideLabel

Try it!

Economic and Business[edit]

Map of places of birth of economists[edit]

#added before 2016-10

#defaultView:Map
SELECT ?person ?name ?coord ?place ?birthplace ?birthyear
WHERE
{
   {?person wdt:P106 wd:Q188094 .} UNION {?person wd:P101 wd:Q8134.}. MINUS {?person wdt:P106 wd:Q188094. ?person wd:P101 wd:Q8134.}
   ?person wdt:P19 ?place .
   ?place wdt:P625 ?coord .
      OPTIONAL { ?person wdt:P569 ?dob .}.
	BIND(YEAR(?dob) as ?birthyear).
   ?person rdfs:label ?name filter (lang(?name) = "en")
   ?place rdfs:label ?birthplace filter (lang(?birthplace) = "en")
}

Try it!

Billionaires[edit]

#added before 2016-10

SELECT ?item ?itemLabel ?billions
WHERE
{
  ?item wdt:P2218 ?worth.
  FILTER(?worth>1000000000).
  BIND(?worth/1000000000 AS ?billions).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?billions)

Try it!

Science[edit]

Biology and Medicine[edit]

Diseases[edit]

The number of existing translations for diseases in Wikidata[edit]

Items used: disease (Q12136)

#added before 2016-10

SELECT ?disease ?doid ?enLabel (count(?language) as ?languages) 
WHERE
{
	?disease wdt:P699 ?doid ;
             rdfs:label ?label ;
             rdfs:label ?enLabel .
    FILTER (lang(?enLabel) = "en")
    
    BIND (lang(?label) AS ?language)
}
group by ?disease ?doid ?enLabel
order by desc(?languages)

Try it!

A network of Drug-disease interactions on infectious diseases (Source: Disease Ontology, NDF-RT and ChEMBL)[edit]
#added before 2016-10
#defaultView:Graph
SELECT DISTINCT ?item ?itemLabel ?rgb ?link
WHERE
{
  VALUES ?toggle { true false }
  ?disease wdt:P699 ?doid;
           wdt:P279+ wd:Q18123741;
           wdt:P2176 ?drug.
  ?drug rdfs:label ?drugLabel.
		FILTER(LANG(?drugLabel) = "en").
  ?disease rdfs:label ?diseaseLabel.
		FILTER(LANG(?diseaseLabel) = "en").
  BIND(IF(?toggle,?disease,?drug) AS ?item).
  BIND(IF(?toggle,?diseaseLabel,?drugLabel) AS ?itemLabel).
  BIND(IF(?toggle,"FFA500","7FFF00") AS ?rgb).
  BIND(IF(?toggle,"",?disease) AS ?link).
}

Try it!

The number of Wikidata items on Diseases and the percentage of those with a pointer to the Disease Ontology[edit]
#added before 2016-10

SELECT (COUNT(?disease) AS ?total) (SUM(?ref) AS ?byDO) (100*?byDO/?total AS ?percent)
WHERE
{
  {?disease wdt:P31 wd:Q12136 }
  UNION
  {?disease wdt:P279 wd:Q12136 .}
  OPTIONAL {
    ?disease p:P699 ?statement.
    BIND(1 AS ?ref).
  }
}

Try it!

Genes[edit]

Human genes updated this week[edit]

The following query uses these:

SELECT DISTINCT ?item ?ncbi_gene ?date_modified
WHERE
{
	?item wdt:P351 ?ncbi_gene ;
          wdt:P703 wd:Q15978631 ; 
          schema:dateModified ?date_modified .
    BIND (now() - ?date_modified as ?date_range)
    FILTER (?date_range < 8)
}

Try it!

Variants[edit]

Counts of gene-variant types sourced from the CIViC database[edit]

The following query uses these:

#defaultView:BarChart
SELECT  ?variant_typeLabel (count(?variant_typeLabel) as ?counts)
WHERE
{
	?item wdt:P3329 ?civic_id ;
          wdt:P31 ?variant_type .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?variant_typeLabel
ORDER BY ?counts

Try it!

Which variant of which gene predicts a positive prognosis in colorectal cancer[edit]

The following query uses these:

SELECT ?geneLabel ?variantLabel 
WHERE
{  
	VALUES ?disease {wd:Q188874}
    ?variant wdt:P3358 ?disease ; # P3358 Positive prognostic predictor
          wdt:P3433 ?gene . # P3433 biological variant of
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Variants that are associated with renal cell carcinoma[edit]

The following query uses these:

# variants that are associated with renal cell carcinoma
SELECT DISTINCT ?civic_id ?item ?itemLabel 
WHERE
{
	VALUES ?property {
                      wdt:P3356 # positive diagnostic predictor 
                      wdt:P3357 # negative diagnostic predictor
                      wdt:P3358 # positive prognostic predicator
                      wdt:P3359 # negative prognostic predictor
                     }
    ?item wdt:P3329 ?civic_id .
    {?item  ?property wd:Q1164529.} # wd:Q1164529 = renal cell carcinoma 
    UNION 
    {?item p:P3354 ?o . # positive therapeutic predictor
     ?o pq:P2175 wd:Q1164529 .}
    UNION 
    {?item p:P3354 ?o . # negative therapeutic predictor
     ?o pq:P2175 wd:Q1164529 .}
      
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

PubMed references in CIViCdb[edit]

The following query uses these:

# variants that are associated with renal cell carcinoma
SELECT DISTINCT  ?reference ?referenceLabel ?pmid
WHERE
{
	?item wdt:P3329 ?civicId ;
          ?property  ?object .
    ?object prov:wasDerivedFrom ?provenance .
    ?provenance pr:P248 ?reference .
    ?reference wdt:P31 wd:Q13442814 ;
               wdt:P698 ?pmid .
    
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!


Variant counts by predictor type[edit]

The following query uses these:

#defaultView:BubbleChart
SELECT  ?propertyLabel (count(?prognostic_type) as ?counts)
WHERE
{
	VALUES ?prognostic_type {wdt:P3354 wdt:P3355 wdt:P3356 wdt:P3357 wdt:P3358 wdt:P3359}
    ?item wdt:P3329 ?civic_id ;
          ?prognostic_type ?prognostic_value .
    ?property wikibase:directClaim ?prognostic_type .  
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?propertyLabel ?prognostic_typeLabel
ORDER BY ?counts

Try it!

Proteins[edit]

Get Wikidata - UniprotId mappings for homo sapiens[edit]

The following query uses these:

SELECT ?item ?itemLabel ?uniprotid ?tax_node
WHERE
{
	?item wdt:P352 ?uniprotid ;
          wdt:P703 wd:Q15978631 .
    
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Metabolites[edit]

Metabolites and the species where they are found in[edit]

The following query uses these:

PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT ?compound ?compoundLabel ?speciesLabel ?sourceLabel ?doi ?wpid WHERE {
  ?compound wdt:P31 wd:Q11173.
  MINUS { ?compound wdt:P31 wd:Q8054. }
  ?compound p:P703 ?statement.
  ?statement rdf:type wikibase:BestRank.
  ?statement ps:P703 ?species.
  OPTIONAL {
    ?statement (prov:wasDerivedFrom/pr:P248) ?source.
    OPTIONAL { ?statement (prov:wasDerivedFrom/pr:P2410) ?wpid. }
    OPTIONAL { ?statement (prov:wasDerivedFrom/pr:P356) ?doi. }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?compound)

Try it!

Find drugs for cancers that target genes related to cell proliferation[edit]

The following query uses these:

#added before 2016-10

#cases where a drug physically interacts with the product of gene known to be genetically associated a disease
#these cases may show opportunities to repurpose a drug for a new disease
#See http://database.oxfordjournals.org/content/2016/baw083.long  and
#http://drug-repurposing.nationwidechildrens.org/search
#an example that was recently validated involved a new link between Metformin wd:Q19484 and cancer survival 
#https://jamia.oxfordjournals.org/content/22/1/179
#currently set up to find drugs for cancers that target genes related to cell proliferation
#adapt by changing constraints (e.g. to 'heart disease' Q190805) or removing them 
SELECT ?drugLabel ?geneLabel ?biological_processLabel ?diseaseLabel
WHERE {
  ?drug wdt:P129 ?gene_product .   # drug interacts with a gene_product 
  ?gene wdt:P688 ?gene_product .  # gene_product (usually a protein) is a product of a gene (a region of DNA)
  ?disease	wdt:P2293 ?gene .    # genetic association between disease and gene 
  ?disease wdt:P279*  wd:Q12078 .  # limit to cancers wd:Q12078 (the * operator runs up a transitive relation..)
  ?gene_product wdt:P682 ?biological_process . #add information about the GO biological processes that the gene is related to  
  #limit to genes related to certain biological processes (and their sub-processes):
  		#apoptosis wd:Q14599311 
  		#cell proliferation wd:Q14818032
  {?biological_process wdt:P279* wd:Q14818032 } # chain down subclass
   UNION 
  {?biological_process wdt:P361* wd:Q14818032 } # chain down part of
    #uncomment the next line to find a subset of the known true positives (there are not a lot of them in here yet)
  #?disease wdt:P2176 ?drug . 	# disease is treated by a drug 
  	SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
	}
}
LIMIT 1000

Try it!

Most common Zika author[edit]

#added before 2016-10

SELECT ?short_author (count(?item) as ?count)
WHERE
{
  { ?item wdt:P921 wd:Q202864 . } UNION { ?item wdt:P921 wd:Q8071861 . }
  ?item wdt:P2093 ?short_author .
}
GROUP BY ?short_author 
ORDER BY DESC(?count)

Try it!

Wikidata scientific articles that contain "zika" in the title[edit]

#added before 2016-10

SELECT ?item ?itemLabel ?_PubMed_ID
WHERE
{
  ?item wdt:P31 wd:Q13442814.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en".
    ?item rdfs:label ?itemLabel.
  }
  FILTER(CONTAINS(LCASE(?itemLabel), "zika"))
  OPTIONAL { ?item wdt:P698 ?_PubMed_ID. }
}
LIMIT 1000

Try it!

Scientific articles that have subject Zika virus or fever and that are used as a reference in another item[edit]

#added before 2016-10

SELECT ?item ?itemLabel ?reference  ?referenceType
WHERE
{
  ?item wdt:P31 wd:Q13442814.#Scientific article
  { ?item wdt:P921 wd:Q202864. } #Zika virus
  UNION
  { ?item wdt:P921 wd:Q8071861. } #Zika fever
  ?reference ?referenceType ?item.  #find references to item having any property and store reference type
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 500

Try it!

Parent taxons of Blue Whale[edit]

#added before 2016-10
 
#defaultView:Graph
SELECT ?item ?itemLabel ?pic ?linkTo
WHERE
{
  wd:Q42196 wdt:P171* ?item
  OPTIONAL { ?item wdt:P171 ?linkTo }
  OPTIONAL { ?item wdt:P18 ?pic }
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en" }
}

Try it!

taxons and what they are named after[edit]

#added before 2016-10

SELECT ?taxon ?eponym ?taxonName ?eponymLabel
WHERE
{
  ?taxon wdt:P31 wd:Q16521;
         wdt:P225 ?taxonName;
         wdt:P138 ?eponym.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?eponym

Try it!

Biologists with Twitter accounts[edit]

SELECT DISTINCT ?personLabel (CONCAT("https://twitter.com/",?twitterName) AS ?twitterlink) ?pic
WHERE {
  ?person wdt:P2002 ?twitterName ;
    wdt:P106 ?occupation .
  OPTIONAL { ?person wdt:P18 ?pic . }
  ?occupation wdt:P279* wd:Q864503 . # all subclasses of biologists
   SERVICE wikibase:label {
     bd:serviceParam wikibase:language "en"
   }
}

Try it!

List of pharmaceutical drugs with picture[edit]

#added before 2016-10

SELECT ?moleculeLabel ?formule ?picture ?molecule
WHERE
{ 
	?molecule  wdt:P31 wd:Q12140
	; wdt:P274 ?formule
	; wdt:P117 ?picture  
	SERVICE wikibase:label {  bd:serviceParam wikibase:language "en, de" . }
} 
ORDER BY ?moleculeLabel

Try it!

Organisms that are located in the female urogential tract and that have a gene with product indole[edit]

#added before 2016-10

SELECT ?organism_name
WHERE
{   
	?organism_item wdt:P276 wd:Q5880
	; rdfs:label ?organism_name . 
	?gene wdt:P703 ?organism_item
	; wdt:P1056 wd:Q319541 . 
	FILTER (LANG(?organism_name) = "en") .    
}

Try it!

Computer Science and Technology[edit]

List of computer files formats[edit]

#added before 2016-10

SELECT DISTINCT ?idExtension ?extension ?mediaType ?idExtensionLabel 
WHERE
{
	?idExtension wdt:P31 wd:Q235557
	; wdt:P1195 ?extension .
	OPTIONAL { ?idExtension wdt:P1163 ?mediaType }
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} 
ORDER BY ?extension ?mediaType

Try it!

List of W3C standards[edit]

#added before 2016-10

SELECT DISTINCT ?standard ?standardLabel ?website
WHERE
{
        ?standard wdt:P1462 wd:Q37033 .
        OPTIONAL{ ?standard wdt:P856 ?website }
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} 
ORDER BY ?standardLabel

Try it!

Oldest software[edit]

SELECT ?software ?softwareLabel ?date (ROUND((NOW() - ?date)/365.2425) AS ?age)
{
  ?software wdt:P31/wdt:P139* wd:Q7397.
  OPTIONAL { ?software wdt:P571 ?date. }
  OPTIONAL { ?software p:P348/pq:P577 ?date. }
  FILTER(BOUND(?date)).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date
LIMIT 10

Try it!

Universities of main programming language authors[edit]

SELECT ?lang ?langLabel ?human ?humanLabel ?educatedat ?educatedatLabel ?coords
{
  ?lang wdt:P31/wdt:P279* wd:Q9143 .
  ?human wdt:P31 wd:Q5 .
  { ?lang wdt:P287 ?human } UNION { ?lang wdt:P170 ?human } UNION { ?lang wdt:P943 ?human } UNION { ?lang wdt:P178 ?human } .

  ?human wdt:P69 ?educatedat .
  ?educatedat wdt:P625 ?coords .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr" }
}
LIMIT 100

Try it!

Websites with OpenAPI endpoints[edit]

SELECT ?database ?databaseLabel ?value WHERE {
  ?database ?p ?wds.
  ?wds ?v ?value.
  ?wdP wikibase:statementProperty ?v.
  ?wdP wikibase:claim ?p.
  ?wds pq:P31 wd:Q27075870.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

E-Readers that support the mobipocket file format[edit]

SELECT ?ereader ?ereaderLabel 

WHERE {
  ?ereader wdt:P31  wd:Q726235 .
  ?ereader wdt:P1072 wd:Q1941622 .
  
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
    
}
  }

Try it!

Software applications ranked in descending order by the number of writable file formats[edit]

#defaultView:BubbleChart
SELECT ?app ?appLabel (COUNT(?format) AS ?count)

WHERE {
  ?app (p:P31/ps:P31/wdt:P279*) wd:Q7397 .
  ?app wdt:P1073 ?format .
            
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
    
}
  }

GROUP BY ?app ?appLabel
ORDER BY DESC(?count)

Try it!

Erdos Numbers and images of people who have oral histories in the Computer History Museum's collection[edit]

#defaultView:ImageGrid
SELECT  ?personLabel  ?image ?Erdos

WHERE {
  ?person wdt:P485 wd:Q964035 .
  ?person wdt:P18 ?image .
  ?person wdt:P2021 ?Erdos
  SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
    
}
  }

Try it!

Chemistry[edit]

Chemical elements and their properties[edit]

#added before 2016-10

SELECT ?elementLabel ?_boiling_point ?_melting_point ?_electronegativity ?_density ?_mass
WHERE
{
  ?element wdt:P31 wd:Q11344.
  ?element wdt:P2102 ?_boiling_point.
  ?element wdt:P2101 ?_melting_point.
  ?element wdt:P1108 ?_electronegativity.
  ?element wdt:P2054 ?_density.
  ?element wdt:P2067 ?_mass. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 100

Try it!

Chemical elements and their isotopes by number of neutrons (min/max)[edit]

#added before 2016-10

SELECT ?element (SAMPLE(?symbol) AS ?symbol) (SAMPLE(?protons) AS ?protons) (MIN(?neutrons) AS ?minNeutrons) (MAX(?neutrons) AS ?maxNeutrons)
WHERE
{
  ?element wdt:P31 wd:Q11344;
           wdt:P1086 ?protons;
           wdt:P246 ?symbol.
  ?isotope wdt:P279 ?element;
           wdt:P1148 ?neutrons.
}
GROUP BY ?element
ORDER BY ?protons

Try it!

Colors of chemical compounds[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?rgb ?colorLabel (COUNT(?compound) AS ?count)
WHERE
{
  ?compound wdt:P31 wd:Q11173;
            wdt:P462 ?color.
  OPTIONAL { ?color wdt:P465 ?rgb. }
  BIND(IF(BOUND(?rgb),?rgb,"CCCCCC") AS ?rgb).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?rgb ?colorLabel

Try it!

All pKa data in Wikidata and the source titles[edit]

#added before 2016-10

SELECT ?compound ?compoundLabel ?pKa ?source ?sourceLabel ?doi
WHERE
{
  ?compound wdt:P31 wd:Q11173 ; p:P1117 ?statement .
  ?statement a wikibase:BestRank ;
    ps:P1117 ?pKa .
  OPTIONAL {
    ?statement prov:wasDerivedFrom/pr:P248 ?source .
    OPTIONAL { ?source wdt:P356 ?doi . }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } #English label
}

Try it!

All CAS registry numbers in Wikidata[edit]

#added before 2016-10

SELECT DISTINCT ?compound ?compoundLabel ?cas
WHERE
{
  ?compound wdt:P231 ?cas .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Chemical compounds in Wikidata sharing the same CAS registry number[edit]

#added before 2016-10

#two chemical compounds with the same CAS registry number
SELECT DISTINCT ?cas ?compound1 ?compound1Label ?compound2 ?compound2Label WHERE {
  ?compound1 wdt:P231 ?cas .
  ?compound2 wdt:P231 ?cas .
  FILTER (?compound1 != ?compound2)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } 
}

Try it!


The number of Chemical compounds in Wikidata sharing the same CAS registry number[edit]

#added before 2016-10

#The number of times a cas registry number is shared by distinct Wikidata items
SELECT ?cas ?items
WHERE
{
	{SELECT DISTINCT ?cas (count(?compound) as ?items) WHERE {
  		?compound wdt:P231 ?cas .
	}
    GROUP BY ?cas }
    FILTER (?items >1)
}
ORDER BY desc(?items)

Try it!

Awarded Chemistry Nobel Prizes[edit]

#defaultView:Timeline
SELECT DISTINCT ?item ?itemLabel ?when (YEAR(?when) as ?date) ?pic
WHERE {
  ?item p:P166 ?awardStat . # … with an awarded(P166) statement
  ?awardStat ps:P166 wd:Q44585 . # … that has the value Nobel Prize in Chemistry (Q35637)
  ?awardStat pq:P585 ?when . # when did he receive the Nobel prize
  
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
OPTIONAL { ?item wdt:P18 ?pic } 
}

Try it!

Space[edit]

Who discovered the most asteroids?[edit]

#added before 2016-10
SELECT ?discoverer ?name (COUNT(?asteroid) AS ?count)
WHERE
{
	?asteroid wdt:P31 wd:Q3863 .
	?asteroid wdt:P61 ?discoverer .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
		?discoverer rdfs:label ?name
	}
}
GROUP BY ?discoverer ?name
ORDER BY DESC(?count)
LIMIT 10

Try it!

Who discovered the most planets? (with list)[edit]

#added before 2016-10
SELECT
	?discoverer ?discovererLabel  
	(COUNT(DISTINCT ?planet) as ?count)
	(GROUP_CONCAT(DISTINCT(?planetLabel); separator=", ") as ?planets)
WHERE
{
	?ppart wdt:P279* wd:Q634 .
	?planet wdt:P31 ?ppart .
	?planet wdt:P61 ?discoverer .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
		?discoverer rdfs:label ?discovererLabel .
		?planet rdfs:label ?planetLabel            
	}
}
GROUP BY ?discoverer ?discovererLabel
ORDER BY DESC(?count)

Try it!

List of space probes with pictures[edit]

#added before 2016-10

#defaultView:ImageGrid
SELECT ?spaceProbeLabel ?date ?picture
WHERE
{
	?spaceProbe wdt:P31 wd:Q26529; 
        wdt:P18 ?picture; 
        wdt:P619 ?date . #mandatory
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "fr,en" .
	}
}
ORDER BY ?date
LIMIT 88

Try it!

Birthplaces of astronauts[edit]

#added before 2016-10

# select all astronauts with name, image, birthdate, birthplace and coordinates of the birthplace

SELECT ?astronaut ?astronautLabel ?image ?birthdate ?birthplace ?coord WHERE {
  ?astronaut ?x1 wd:Q11631;
  wdt:P18 ?image;
  wdt:P569 ?birthdate;
  wdt:P19 ?birthplace.
  
  ?birthplace wdt:P625 ?coord
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?birthdate)

Try it!

Scientists[edit]

Number of scientists per gender[edit]

#added before 2016-10
SELECT ?gender (count(distinct ?human) as ?number)
WHERE
{
	?human wdt:P31 wd:Q5
	; wdt:P21 ?gender
	; wdt:P106/wdt:P279* wd:Q901 .
}
GROUP BY ?gender
LIMIT 10

Try it!

Most eponymous mathematicians[edit]

#added before 2016-10

SELECT ?eponym ?eponymLabel ?count ?sample ?sampleLabel
WHERE
{
	{
	SELECT ?eponym (COUNT(?item) as ?count) (SAMPLE(?item) AS ?sample)
	WHERE
	{
		?item wdt:P138 ?eponym.
		?eponym wdt:P106 wd:Q170790.
	}
	GROUP BY ?eponym
	}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY DESC(?count)

Try it!

Authors of scientific articles by occupation[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?occupationLabel (count(DISTINCT ?author) as ?count) 
WHERE
{
        ?object wdt:P31 wd:Q13442814
        ; wdt:P50 ?author .
        ?author wdt:P106 ?occupation .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr" }
} 
GROUP BY ?occupationLabel
ORDER BY DESC(?count)

Try it!

Authors of scientific articles who received a Nobel prize[edit]

#added in 2016-10

#Authors of scientific articles who received a Nobel prize
SELECT ?item ?itemLabel ?person ?personLabel ?_image ?award ?awardLabel
WHERE {
  ?person wdt:P166 ?award ; #person received an award
          wdt:P31 wd:Q5 . #person is instance of human
  ?award wdt:P279* wd:Q7191 . #award is a Nobel Prize
  ?item wdt:P50 ?person ; #person is an author of item
        wdt:P31 wd:Q13442814 . #item is a scientific article
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  
OPTIONAL { ?person wdt:P18 ?_image. } #Wikimedia Commons has an image of person
}

Try it!

Using VALUES for extracting scientific articles of specific authors[edit]

#added before 2016-10

SELECT ?entity ?desc ?author WHERE {
  VALUES ?wd_author {wd:Q18016466} #initialize "?wd_author" with the Wikidata item "Lydia Pintscher"  
  
  ?entity wdt:P31 wd:Q13442814. #filter by scientific articles
  ?entity wdt:P50 ?wd_author.
  
  ?wd_author rdfs:label ?author. 
  FILTER((LANG(?author)) = "en").
  
  ?entity rdfs:label ?desc.
  FILTER((LANG(?desc)) = "en").  
}

Try it!

Female scientists with most number of sitelinks (but not English Wikipedia)[edit]

#added before 2016-10

#Female scientists with most number of sitelinks (but not English Wikipedia)
PREFIX schema: <http://schema.org/>

SELECT ?item ?itemLabel (COUNT(DISTINCT ?sitelink) AS ?linkcount) WHERE {
    ?item wdt:P31 wd:Q5 .
    ?item wdt:P21 wd:Q6581072 .
    ?item wdt:P106 wd:Q901 .
    ?sitelink schema:about ?item .
  FILTER NOT EXISTS {
    ?article schema:about ?item .
    ?article schema:inLanguage "en" .
    ?article schema:isPartOf <https://en.wikipedia.org/>
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,de,es,ar,fr" }
}
GROUP BY ?item ?itemLabel
ORDER BY DESC(?linkcount)

Try it!

Inventors killed by their own invention[edit]

#added before 2016-10
SELECT ?inventor ?inventorLabel ?gadet ?gadgetLabel
WHERE {
  ?inventor wdt:P157 ?gadget .
  ?gadet wdt:P61 ?inventor .
  SERVICE wikibase:label { 
    bd:serviceParam wikibase:language "en" . 
    ?inventor rdfs:label ?inventorLabel .
    ?gadget rdfs:label ?gadgetLabel .
  }
}

Try it!

Most cited female authors[edit]

#added 2016-12
##defaultView:BubbleChart
SELECT ?author ?authorLabel (COUNT(?publication) AS ?count)
WHERE
{
    ?item wdt:P2860 ?publication . #citations
    ?publication wdt:P50 ?author . #authors
    ?author wdt:P21 wd:Q6581072. #females
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
    }
}
GROUP BY ?author ?authorLabel
ORDER BY DESC(?count)

Try it!

Scientific literature[edit]

PMID-DOI mappings[edit]

#added before 2016-10

SELECT DISTINCT ?pmid ?doi
WHERE
{
	?item wdt:P698 ?pmid ;
              wdt:P356 ?doi .
}

Try it!

The number of statements by DOI[edit]

SELECT ?doi (COUNT (?entry) as ?entries)
{
  ?entry ?p ?statement .
  ?statement prov:wasDerivedFrom/pr:P248/wdt:P356 ?doi .
} 
GROUP BY ?doi 
ORDER BY DESC(?entries)

Try it!

number of statements backed by a reference with a DOI[edit]

#added before 2016-10

SELECT (COUNT (?statement) as ?statements)
WHERE
{
  ?entry ?p ?statement .
  ?statement prov:wasDerivedFrom/
       <http://www.wikidata.org/prop/reference/P248>/
       wdt:P356 ?doi .
}

Try it!

Statements originating from a specific DOI[edit]

#added before 2016-10

SELECT ?entryRes ?entry ?statement
WHERE
{
  ?entryRes ?p ?statement ;
    rdfs:label ?entry .
  ?statement prov:wasDerivedFrom/
       <http://www.wikidata.org/prop/reference/P248>/
       wdt:P356 "10.1021/ja01577a030" .
   FILTER(lang(?entry) = "en")
}

Try it!

Translations of the Disease Ontology term DOID:399 (Tuberculosis)[edit]

#added before 2016-10

SELECT ?English ?language ?label
WHERE
{
	?disease wdt:P699 "DOID:399"
	; rdfs:label ?English
	; rdfs:label ?label .
	FILTER (LANG(?English) = "en")
	BIND(LANG(?label) as ?languageCode) 
	?languageCode ^ps:P424 ?lstatement  .	?lstatement pq:P794 wd:Q22283033	; ^p:P424 ?wdLanguage .
	?wdLanguage rdfs:label ?language .
	FILTER (LANG(?language)="en")
}

Try it!

Library and Information Science journals[edit]

#added before 2016-10

SELECT DISTINCT ?journal ?name WHERE {
    ?journal wdt:P31 wd:Q5633421 . # is scientific journal
    {
            { ?journal wdt:P921 wd:Q199655 }   # with topic library science
      UNION { ?journal wdt:P921 wd:Q16387 }    # and/or topic information science
      UNION { ?journal wdt:P921 wd:Q13420675 } # and/or topic library and information science   
    }
    SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
        ?journal rdfs:label ?name .
    }
}

Try it!

Most popular subjects of scientific articles[edit]

select (count(?work) as ?count) ?subject ?subjectLabel where {
  ?work wdt:P31 wd:Q13442814; 
        wdt:P921 ?subject .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
group by ?subject ?subjectLabel
order by desc(?count)
limit 200

Try it!

Math[edit]

Mathematical proofs[edit]

#added before 2016-10

SELECT ?proof ?proofLabel
WHERE
{
  ?proof wdt:P31 wd:Q11538.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

Databases listed in Wikidata and if available applicable licenses[edit]

#added before 2016-10

SELECT DISTINCT *
WHERE
{
	?item 	wdt:P31 wd:Q8513 ;
		rdfs:label ?name .
	OPTIONAL {	?item  wdt:P275 ?licenseItem .
			?licenseItem rdfs:label ?license . 
			FILTER (LANG(?license) = "en")}
	FILTER (LANG(?name) = "en")	
}

Try it!

Scientists who have worked together but whose Erdos numbers don’t reflect that[edit]

#added before 2016-10

# Finds authors who have published scientific articles together,
# but whose Erdos numbers are more than one apart.
# These would appear to violate the definition of the Erdos number.

SELECT
	# Q#s
	?paper
	?author1
	?author2
	# title (either from title statement or label)
	(IF(BOUND(?title), ?title, ?paperLabel) AS ?title)
	# author labels (should be names) and their Erdos numbers
	?author1Label
	?erdos1
	?author2Label
	?erdos2
	# distance between Erdos numbers
	?distance
WHERE
{
	# paper, instance of or subclass of scientific article; also has two authors
	?paper wdt:P31/wdt:P279* wd:Q13442814;
	         wdt:P50 ?author1, ?author2.
	# if it has a title, we’ll grab that as well, but it’s also okay if there’s no title
	OPTIONAL { ?paper wdt:P1476 ?title. }
	# grab Erdos numbers of the two authors
	?author1 wdt:P2021 ?erdos1.
	?author2 wdt:P2021 ?erdos2.
	# introduce a new variable for the difference of the Erdos numbers
	BIND(?erdos2 - ?erdos1 AS ?distance).
	# select those cases where the distance is > 1
	# (note: by *not* taking the absolute value of the distance, we avoid getting duplicated cases because the author variables might be swapped)
	FILTER(?distance > 1).
	# get *Label variables automagically
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
# sort by distance first (descending), then by first author, then by second author
ORDER BY DESC(?distance) ?author1Label ?author2Label

Try it!


Fictional universes with most fictional planets[edit]

#added before 2016-10

SELECT ?universe (SAMPLE(?label) AS ?label) (COUNT(?planet) AS ?count)
WHERE
{
  ?planet wdt:P31 wd:Q2775969;
          wdt:P1080 ?universe.
  ?universe rdfs:label ?label.
  FILTER(LANG(?label) = "en").
}
GROUP BY ?universe
ORDER BY DESC(?count)

Try it!

Objects with most mass[edit]

#added before 2016-10
SELECT ?object ?objectLabel (MAX(?mass) AS ?mass)
WHERE
{
  ?object p:P2067/psv:P2067 [
    wikibase:quantityAmount ?baseMass;
    wikibase:quantityUnit [
      p:P2370/psv:P2370 [
        wikibase:quantityAmount ?unitMass;
        wikibase:quantityUnit wd:Q11570
      ]
    ]
  ].
  BIND(?baseMass * ?unitMass AS ?mass).
  MINUS { ?object wdt:P31 wd:Q3647172. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?object ?objectLabel
ORDER BY DESC(?mass)

Try it!

Biological databases listed in Wikidata and if available applicable licenses[edit]

#added before 2016-10
 
SELECT DISTINCT *
WHERE
{
	?item wdt:P31 wd:Q4117139 ;
          rdfs:label ?name .
    OPTIONAL {?item  wdt:P275 ?licenseItem .
    ?licenseItem rdfs:label ?license . 
    FILTER (LANG(?license) = "en")}
    FILTER (LANG(?name) = "en")	
}

Try it!


American universities founded before the states they reside in were created[edit]

#added before 2016-10
 SELECT ?uLabel ?founded ?stateLabel ?stateStart
WHERE
{
	?u wdt:P31/wdt:P279* wd:Q3918 .
	?u wdt:P131+ ?state .
	?state wdt:P31 wd:Q35657 .
	?state wdt:P571 ?stateStart .
	?u wdt:P571 ?founded .
	FILTER (?founded < ?stateStart) .
	SERVICE wikibase:label {
		bd:serviceParam wikibase:language "en" .
	}
}
LIMIT 10

Try it!

History[edit]

US presidents and spouses[edit]

#added before 2016-10
#TEMPLATE={"template":"Presidents of ?country and their spouses","variables":{"?country":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q6256 . }"} } }

SELECT ?p ?pLabel ?ppicture ?w ?wLabel ?wpicture WHERE {
  BIND(wd:Q30 AS ?country)
  ?country (p:P6/ps:P6) ?p.
  ?p wdt:P26 ?w.
  OPTIONAL {
    ?p wdt:P18 ?ppicture.
    ?w wdt:P18 ?wpicture.
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

US presidents & causes of death[edit]

List of presidents with causes of death[edit]

#added before 2016-10
SELECT ?h ?cause ?hl ?causel 
WHERE 
{
	?h wdt:P39 wd:Q11696 .
	?h wdt:P509 ?cause .
	OPTIONAL {  
		?h rdfs:label ?hl filter (lang(?hl) = "en") .
	}
	OPTIONAL { 
		?cause rdfs:label ?causel filter (lang(?causel) = "en"). 
	}
}

Try it!

Presidents and their causes of death ranking[edit]

#added before 2016-10

#defaultView:BubbleChart
SELECT ?cid ?cause (count(*) as ?count)
WHERE
{
	?pid wdt:P39 wd:Q11696 .
	?pid wdt:P509 ?cid .
	OPTIONAL {
		?cid rdfs:label ?cause filter (lang(?cause) = "en") .
	}
}
GROUP BY ?cid ?cause
ORDER BY DESC(?count) ASC(?cause)

Try it!

Politicians who died of cancer (of any type)[edit]

#added before 2016-10
SELECT ?politician ?cause ?politician_label ?cause_of_death_label 
WHERE 
{
	?politician wdt:P106 wd:Q82955 .    # find items that have "occupation (P106): politician (Q82955)"
	?politician wdt:P509 ?cause .       # with a P509 (cause of death) claim
	?cause wdt:P279* wd:Q12078 .        # ... where the cause is a subclass of (P279*) cancer (Q12078)
	# ?politician wdt:P39 wd:Q11696 .   # Uncomment this line to include only U.S. Presidents
	  
	OPTIONAL {?politician rdfs:label ?politician_label filter (lang(?politician_label) = "en") .} 
	OPTIONAL {?cause rdfs:label ?cause_of_death_label filter (lang(?cause_of_death_label) = "en").}
}
ORDER BY ASC (?politician)

Try it!

List of popes[edit]

#added before 2016-10

SELECT ?link ?linkLabel ?picture ?age
WHERE
{
	?link wdt:P31 wd:Q5 ; 
          p:P39 [ ps:P39 wd:Q19546 ; pq:P580 ?startTime ] .
	OPTIONAL { ?link wdt:P569 ?dateOfBirth }
	OPTIONAL { ?link wdt:P18 ?picture }
	OPTIONAL { ?link wdt:P570 ?dateOfDeath }
	BIND(YEAR(?dateOfDeath) - YEAR(?dateOfBirth) as ?age)
	SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en" }
}
ORDER BY DESC(?startTime)

Try it!

Years with 3 popes[edit]

#added before 2016-10

SELECT ?year ?pope1Label ?pope2Label ?pope3Label
WHERE
{
  ?pope2 p:P39 [
           ps:P39 wd:Q19546;
           pq:P580 ?p2s;
           pq:P582 ?p2e;
           pq:P1365 ?pope1;
           pq:P1366 ?pope3
         ].
  ?pope1 p:P39 [
           ps:P39 wd:Q19546;
           pq:P582 ?p1e
         ].
  ?pope3 p:P39 [
           ps:P39 wd:Q19546;
           pq:P580 ?p3s
         ].
  BIND(YEAR(?p2s) AS ?year).
  FILTER(YEAR(?p2e) = ?year && YEAR(?p1e) = ?year && YEAR(?p3s) = ?year).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?year

Try it!

Popes with children[edit]

#added before 2016-10

# All popes with number of children 
SELECT  (SAMPLE(?father) as ?father) ?fatherLabel  (SAMPLE(?picture) as ?picture) (COUNT(?father) as ?children)
WHERE
{
	?subj wdt:P22 ?father .
  	?father wdt:P31 wd:Q5 .
  	?father wdt:P39 wd:Q19546 .
	OPTIONAL {
		?father wdt:P18 ?picture .
		}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?fatherLabel
ORDER BY DESC(?children)
LIMIT 50

Try it!

French heads of government by length of service[edit]

SELECT DISTINCT ?item ?itemLabel ?positionLabel ?picture ?as ?start ?end ?days
{
  ?item wdt:P31 wd:Q5 ;
        wdt:P18 ?picture ;
        p:P39 ?position_statement .
  ?position_statement ps:P39 ?position ;
                      pq:P580 ?start FILTER (?start >= "1815-01-01T00:00:00Z"^^xsd:dateTime) .
  ?position wdt:P279* wd:Q15135541 .
  OPTIONAL { ?position_statement pq:P582 ?x }
  OPTIONAL {
    ?position_statement pq:P794/rdfs:label ?as filter (lang(?as) = "en") .
  }
  bind(if(bound(?x), ?x, NOW()) as ?end )
  bind(floor(?end - ?start) as ?days)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
} 
ORDER BY DESC(?days) ?itemLabel

Try it!

List of countries in 1754[edit]

#added before 2016-10
SELECT ?h ?hLabel ?inception ?dissolved ?coor
WHERE
{
	VALUES ?countryclass { wd:Q3024240 wd:Q6256 }
  	?h wdt:P31 ?countryclass  .
	?h wdt:P571 ?inception .
	OPTIONAL { ?h wdt:P576 ?dissolved } .
	FILTER (?inception < "1755-01-01T00:00:00Z"^^xsd:dateTime)
	FILTER (?dissolved >= "1755-01-01T00:00:00Z"^^xsd:dateTime || !Bound(?dissolved) )
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
	OPTIONAL { ?h wdt:P625 ?coor } .
}
ORDER BY ?inception

Try it!

Population in Europe after 1960[edit]

#added before 2016-10

SELECT  ?objectLabel    (YEAR(?date) as ?year) 
        ?population     (?objectLabel as ?Location)
WHERE
{
        ?object	wdt:P31 wd:Q185441 
        ;	p:P1082 ?populationStatement .
        ?populationStatement    ps:P1082 ?population
        ;	pq:P585 ?date .
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }                
	FILTER (YEAR(?date) >= 1960)
} 
ORDER BY ?objectLabel ?year

Try it!

Locations of air accidents[edit]

#added before 2016-10
 SELECT ?label ?coord ?place
WHERE
{
   ?subj wdt:P31 wd:Q744913  .
   ?subj wdt:P625 ?coord .
   ?subj rdfs:label ?label filter (lang(?label) = "en")
}

Try it!

Most prolific fathers[edit]

#added before 2016-10
 SELECT  (SAMPLE(?father) as ?father) ?fatherLabel  (SAMPLE(?picture) as ?picture) (COUNT(?father) as ?children)
WHERE
{
	?subj wdt:P22 ?father .
	OPTIONAL {
		?father wdt:P18 ?picture .
		}
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?fatherLabel
ORDER BY DESC(?children)
LIMIT 50

Try it!

List of suicide attacks[edit]

#added before 2016-10

SELECT ?h ?hLabel ?location (CONCAT("injured: ",str(?injured)) as ?injuredl) (concat("dead: ",str(?dead)) as ?deadl) ?date ?image
WHERE
{
        ?h wdt:P31 ?attack.  
    values (?attack) {
      (wd:Q18493502)
      (wd:Q217327)
      
      
    }
    optional {    ?h wdt:P1339 ?injured . } 
    optional {    ?h wdt:P1120 ?dead. }
    optional {    ?h wdt:P276?/wdt:P625 ?location }
    optional {    ?h wdt:P585 ?date }
    optional {    ?h wdt:P18 ?image }
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

People who died by burning - on a timeline[edit]

#added before 2016-10

#defaultView:Timeline
SELECT ?person ?personLabel ?date
WHERE
{
  ?person wdt:P31 wd:Q5;
          wdt:P509 wd:Q468455;
          wdt:P570 ?date.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?date

Try it!

People who lived in the same period as another person[edit]

#added before 2016-10

select ?person ?personLabel ?personDescription ?birth ?death ?age
WHERE
{
  ?person wdt:P31 wd:Q5. # instance of human
  ?person wdt:P569 ?birth . # birth date
  ?person wdt:P570 ?death . # death date
  bind( year(?death)-year(?birth) as ?age ) # Make a new variable called ?age that we can use
  filter (?age > 10 && ?age < 100) # Only find people with realistic ages  
  filter (?birth > "1452-04-15"^^xsd:dateTime && ?death < "1519-05-02"^^xsd:dateTime) # And between these two dates
  service wikibase:label { bd:serviceParam wikibase:language "en". } # used to display a label
}

Try it!

List of torture devices[edit]

#added before 2016-10
 SELECT ?thing ?thingLabel ?image
WHERE
{
  ?thing wdt:P366 wd:Q132781 .
  ?thing wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!

Animals that were executed[edit]

#added before 2016-10

SELECT ?animal ?animalLabel ?died ?mannerOfDeathLabel ?image
WHERE
{
  ?animal wdt:P31/wdt:P31 wd:Q16521; # instance of some taxon (does not include human)
          wdt:P509 ?mannerOfDeath.
  ?mannerOfDeath wdt:P279* wd:Q8454. # some subclass of capital punishment
  OPTIONAL { ?animal wdt:P570 ?died. }
  OPTIONAL { ?animal wdt:P18 ?image. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?died

Try it!

People who were stateless for some time[edit]

The following query uses these:

# persons who were stateless (country of citizenship: no value) for some time (start time and end time qualifiers)
SELECT ?person ?personLabel ?start ?end WHERE {
  ?person wdt:P31 wd:Q5;
          p:P27 [
            a wdno:P27;
            pq:P580 ?start;
            pq:P582 ?end
          ].
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?end - ?start)

Try it!

Culture[edit]

Museums[edit]

Museums in Brittany[edit]

#added before 2016-10
SELECT DISTINCT ?museumLabel ?museumDescription ?villeId ?villeIdLabel (?villeIdLabel AS ?ville) ?coord ?lat ?lon
WHERE
{
  ?museum wdt:P539 ?museofile.  # french museofile Id
  ?museum wdt:P131* wd:Q12130. # in Brittany
  ?museum wdt:P131 ?villeId. #city of the museum
  # ?object wdt:P166 wd:Q2275045 # that have french label "musées de France"
  OPTIONAL {?museum wdt:P856 ?link.}     # official website
  OPTIONAL {?museum wdt:P625 ?coord .} # geographic coord
  OPTIONAL {
    ?museum p:P625 ?statement.
    ?statement psv:P625 ?node.
    ?node wikibase:geoLatitude ?lat.
    ?node wikibase:geoLongitude ?lon.
   }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr". } #french label
}
ORDER BY  ?villeIdLabel

Try it!

All museums in Barcelona with coordinates[edit]

#added before 2016-10

#All museums (including subclass of museum) in Barcelona with coordinates
SELECT DISTINCT ?item ?name ?coord ?lat ?lon
WHERE
{
 ?item wdt:P131* wd:Q1492 .
 ?item wdt:P31/wdt:P279* wd:Q33506 .
 ?item wdt:P625 ?coord .
 ?item p:P625 ?coordinate .
 ?coordinate psv:P625 ?coordinate_node .
 ?coordinate_node wikibase:geoLatitude ?lat .
 ?coordinate_node wikibase:geoLongitude ?lon .
 SERVICE wikibase:label {
 bd:serviceParam wikibase:language "ca" .
 ?item rdfs:label ?name
 }
}
ORDER BY ASC (?name)

Try it!

Museums in Antwerp[edit]

#added before 2016-10

#defaultView:Map
SELECT ?item ?itemLabel ?coordinates
WHERE
{
  ?item wdt:P31/wdt:P279* wd:Q33506 ;
        wdt:P131 wd:Q12892 ;
        wdt:P625 ?coordinates .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "nl, en" }
  }

Try it!

Performing arts[edit]

Characters portrayed by most actors[edit]

#added before 2016-10

SELECT ?character ?characterLabel (COUNT(?actor) AS ?count)
WHERE
{
  {
    SELECT DISTINCT ?character ?actor
    WHERE {
      ?film p:P161 [
        ps:P161 ?actor;
        pq:P453 ?character
      ].
      #?character wdt:P31 wd:Q5. # uncomment to filter for real people
    }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?character ?characterLabel
ORDER BY DESC(?count)
LIMIT 25

Try it!

List of theatre plays[edit]

#added before 2016-10

SELECT ?play ?playLabel
WHERE 
{
	?play wdt:P31 wd:Q25379 .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en,es,pt,de,fr,ja,zh" . }
}
LIMIT 1000