【发布时间】:2020-04-12 19:08:18
【问题描述】:
我还是 XQuery 的新手,但我几乎已经弄清楚了这个查询,但它只需要返回具有最多作者的元素的 proteinID 和 numberOfAuthors,但是它目前返回所有这些而不是只返回作者数量最多的元素。
我的查询是
for $i in doc("test.xml")/ProteinDatabase/ProteinEntry
let $author-count := count($i/reference/refinfo/authors)
let $proteinID := $i/@id
where $author-count = max($author-count)
order by $author-count descending
return ((<proteinID>{data($proteinID)}</proteinID>,
<numberOfAuthors>{data($author-count)}</numberOfAuthors>))
返回:
<proteinID>QRHUA4</proteinID>
<numberOfAuthors>47</numberOfAuthors>
<proteinID>PLHU</proteinID>
<numberOfAuthors>29</numberOfAuthors>
<proteinID>LPHUB</proteinID>
<numberOfAuthors>29</numberOfAuthors>
等等。
我只想返回第一个 proteinID,最高的是 47,如下所示:
<proteinID>QRHUA4</proteinID>
<numberOfAuthors>47</numberOfAuthors>
我已经尝试了一些东西,比如我在其中的 where 语句
where $author-count = max($author-count)
但它似乎并没有真正做任何事情。我也尝试了一些定位的东西,只选择了第一个索引,但它似乎只返回 ID QRHUA4,而不是 numberOfAuthors
【问题讨论】:
-
请发布一些示例 xml
-
当然很抱歉,它只是很长,所以我省略了它
-
最少的样本就可以了
-
用一个例子更新了 OP