[英]Why does my range search in XQuery not work and returns too many elements?
New to XQuery and probably a noob q. XQuery的新手,可能是菜鸟q。 I installed a BaseX db as my sandbox (which included a sample file etc/factbook.xml).
我安装了一个BaseX数据库作为我的沙箱(其中包含一个示例文件etc / factbook.xml)。 I constructed a simple query which I thought would return all 'cities' with population > 10million.
我构建了一个简单的查询,我认为它将返回人口超过1000万的所有“城市”。
for $x in doc("etc/factbook.xml")/mondial/country
where $x/city/population > 10000000.0
return $x/city
but I'm getting cities with lower populations, any insight? 但是我的人口较少,有洞察力的城市?
<city id="f0_1726" country="f0_553" longitude="126.967" latitude="37.5667">
<name>Seoul</name>
<population year="95">10229262</population>
</city>
<city id="f0_10300" country="f0_553">
<name>Kunsan</name>
<population year="95">266517</population>
</city>
(I've only included first two but many more both < and > 10million)
You're returning all countries that have a city with population larger than 10 millions. 您将返回所有人口超过1000万的城市 。 Loop over the cities instead (and please, use meaningful variable names):
循环遍布城市(请使用有意义的变量名称):
for $city in doc("etc/factbook.xml")/mondial/country/city
where $city/population > 10000000
return $city
Or just go for an XPath expression doing the same: 或者只是去做同样的XPath表达式:
doc("etc/factbook.xml")/mondial/country/city[population > 10000000]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.