Skip to content

Instantly share code, notes, and snippets.

@HRezaei
Created November 10, 2016 18:12
Show Gist options
  • Save HRezaei/3006a895f2ea5200b2463f8ebeda54bd to your computer and use it in GitHub Desktop.
Save HRezaei/3006a895f2ea5200b2463f8ebeda54bd to your computer and use it in GitHub Desktop.
A sample SPARQL query to fetch cities of Iran with population over 10,000
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 >= 10000).
?city wdt:P17 wd:Q794.
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 "fa". }
}
GROUP BY ?city ?cityLabel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment