如何在某个国家/地区查找人口超过X的城市 [英] How to find cities with more than X population in a certain country

查看:110
本文介绍了如何在某个国家/地区查找人口超过X的城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力寻找丹麦人口超过10万的城市。

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>
}

使用此代码,我可以找到人口超过10万的城市:

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.

推荐答案

简单:

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

换句话说:查找所有类型为丹麦的城市或城镇的事物,并找到其人口。您可以使用';'而不是'。'来简化查询,避免重复'resource'。

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 .

(如果您习惯使用SQL'。'本质上是自然连接:您拥有?resource两侧,因此请加入该值)

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

这篇关于如何在某个国家/地区查找人口超过X的城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆