我不确定我在这里做错了什么,但我试图通过使用“where”设置两个条件,它们各自单独工作,但是当我将它们组合起来时,我会得到每个文件的转储。
如果我只是:
for $i in collection("/db/people")
where $i//lastname="Smith"
return $i
我得到两个列表,因为有两种类型(a 和 b)。
如果我有
for $i in collection("/db/people")
where $i//type="a"
return $i
我得到了 538 个列表,其中所有内容都是“a”类型。
但是,如果我有:
for $i in collection("/db/people")
where $i//type="a" and $i//lastname="Smith"
return $i
我得到了所有文件。为什么它不只给我一个具有我指定的名称和类型的文件?看来我错过了一些明显的东西!
最佳答案
您可以在 http://try.zorba-xquery.com/ 上尝试您的解决方案,效果很好。 例如:
let $people := (<people><type>a</type><lastname>Smith</lastname></people>, <people><type>a</type><lastname>Foobar</lastname></people>)
for $i in $people
where $i//type="a" and $i//lastname="Smith"
return $i
关于xquery - 如何在 xQuery 中组合Where 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9010828/