How to find cities with more than X population in a certain country

混江龙づ霸主 提交于 2019-12-06 04:26:49

问题


I'm trying to find cities in Denmark with more than 100 000 in population.

I can find all the cities in Denmark with this code:

SELECT ?s ?o 
WHERE { 
   ?s a <http://dbpedia.org/class/yago/CitiesAndTownsInDenmark>
}

And with this code I can find cities with more than 100 000 in population:

SELECT ?resource ?value 
WHERE { 
   ?resource <http://dbpedia.org/property/populationTotal> ?value 
   FILTER (?value > 100000)
}
ORDER BY ?resource ?value

I would appreciate help about how to combine these queries.


回答1:


Simple:

SELECT ?resource ?value
WHERE { 
   ?resource a <http://dbpedia.org/class/yago/CitiesAndTownsInDenmark> .
   ?resource <http://dbpedia.org/property/populationTotal> ?value .
   FILTER (?value > 100000)
}
ORDER BY ?resource ?value

In other words: find all the things with type "City or Town in Denmark", and find their populations. You can abbreviate the query, avoiding repetition of 'resource', using ';' rather than '.':

?resource a <http://dbpedia.org/class/yago/CitiesAndTownsInDenmark> ;
          <http://dbpedia.org/property/populationTotal> ?value .

(If you're used to SQL '.' is essentially a natural join: you have ?resource on each side, so join on that value)



来源:https://stackoverflow.com/questions/15091228/how-to-find-cities-with-more-than-x-population-in-a-certain-country

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!