query-86c4aec297f3cd93a21b01b08758d8e2
Get median year for discovery of elements
SELECT ?item ?itemLabel ?year ?lower_or_equal_values ?higher_or_equal_values
WITH
{
SELECT ?item ?year
WHERE
{
?item wdt:P31 wd:Q11344 .
?item wdt:P575 ?time_of_discovery .
BIND (YEAR(?time_of_discovery) AS ?year)
}
} AS %data_set
WITH
{
SELECT ?item ?year (COUNT(?year2) AS ?lower_or_equal_values)
WHERE
{
INCLUDE %data_set
{ SELECT (?year AS ?year2) WHERE { INCLUDE %data_set } }
FILTER (?year2 <= ?year)
}
GROUP BY ?item ?year
} AS %lower_or_equal_values
WITH
{
SELECT ?item ?year (COUNT(?year2) AS ?higher_or_equal_values)
WHERE
{
INCLUDE %data_set
{ SELECT (?year AS ?year2) WHERE { INCLUDE %data_set } }
FILTER (?year2 >= ?year)
}
GROUP BY ?item ?year
} AS %higher_or_equal_values
WHERE
{
INCLUDE %lower_or_equal_values
INCLUDE %higher_or_equal_values
FILTER (?higher_or_equal_values <= ?lower_or_equal_values)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?lower_or_equal_values
LIMIT 1
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Get median year for discovery of elements
SELECT ?item ?itemLabel ?year ?lower_or_equal_values ?higher_or_equal_values
WHERE
{
{
SELECT ?item ?year (COUNT(?year2) AS ?lower_or_equal_values)
WHERE
{
{
SELECT ?item ?year
WHERE
{
?item wdt:P31 wd:Q11344 .
?item wdt:P575 ?time_of_discovery .
BIND (YEAR(?time_of_discovery) AS ?year)
}
} { SELECT (?year AS ?year2) WHERE {
{
SELECT ?item ?year
WHERE
{
?item wdt:P31 wd:Q11344 .
?item wdt:P575 ?time_of_discovery .
BIND (YEAR(?time_of_discovery) AS ?year)
}
}} }
FILTER (?year2 <= ?year)
}
GROUP BY ?item ?year
}
{
SELECT ?item ?year (COUNT(?year2) AS ?higher_or_equal_values)
WHERE
{
{
SELECT ?item ?year
WHERE
{
?item wdt:P31 wd:Q11344 .
?item wdt:P575 ?time_of_discovery .
BIND (YEAR(?time_of_discovery) AS ?year)
}
} { SELECT (?year AS ?year2) WHERE {
{
SELECT ?item ?year
WHERE
{
?item wdt:P31 wd:Q11344 .
?item wdt:P575 ?time_of_discovery .
BIND (YEAR(?time_of_discovery) AS ?year)
}
}} }
FILTER (?year2 >= ?year)
}
GROUP BY ?item ?year
} FILTER (?higher_or_equal_values <= ?lower_or_equal_values)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY ?lower_or_equal_values
LIMIT 1