如何获得Marklogic Xquery中具有特定值的特定记录的计数

发布于 2025-02-11 00:05:56 字数 444 浏览 2 评论 0原文

我正在尝试获得给定条件的记录。

计算辅助价格大于1000的集合中所有文档中的辅助价格的数量。

我正在尝试以下Xquery,这给了我以下响应:

在9007.0781 ms中返回了532个项目的序列。 (与先前的运行相比-361.0691 ms。)

,并在所有532行中在每行中打印1个值。

但是,我的预期结果是将计数作为结果:532在我的结果页面中。

您可以在这里帮助确定Xquery问题吗?

xquery version "1.0-ml";
for $x in collection("GTM2_Shipment")
where ($x/*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000) 
return (count($x))

I am trying to get count of a record for a given condition.

Count the number of Ancillary Price in all documents in a collection where the Ancillary Price is greater than 1000.

I am trying the below XQuery for that, it gives me this below response:

Returned sequence of 532 items in 9007.0781 ms. (-361.0691 ms. compared to previous run)

And along with it prints value of 1 in each row for all 532 rows.

However my expected result is to get the count as result: 532 in my result page.

Can you please help to identify the XQuery issue here?

xquery version "1.0-ml";
for $x in collection("GTM2_Shipment")
where ($x/*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000) 
return (count($x))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等风来 2025-02-18 00:05:56

结构略有不正确。

参考: https://wwwwww.w3schools.com/xml/xml/xml/xquery_flwor.asp

em>尝试:

xquery version "1.0-ml";
fn:count(
   for $x in collection("GTM2_Shipment")
   where ($x/*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000) 
   return $x
)

或简单地:

xquery version "1.0-ml";
fn:count(collection("GTM2_Shipment")[./*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000])

,最终将不会扩展。
对您自己的文档中每个装运的数据进行建模,然后您可以使用以下估算值:

xquery version "1.0-ml";
xdmp:estimate(cts:search(fn:count(collection("GTM2_Shipment"), {a range query to your quotePrice }))

The structure is slightly incorrect.

Ref: https://www.w3schools.com/xml/xquery_flwor.asp

Try:

xquery version "1.0-ml";
fn:count(
   for $x in collection("GTM2_Shipment")
   where ($x/*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000) 
   return $x
)

Or simply:

xquery version "1.0-ml";
fn:count(collection("GTM2_Shipment")[./*:Shipment/*:Ancillary/*:QuotePrice/text() > 1000])

However, eventually these will not scale.
Model your data where each shipment is in it's own document and then you can use an estimate such as:

xquery version "1.0-ml";
xdmp:estimate(cts:search(fn:count(collection("GTM2_Shipment"), {a range query to your quotePrice }))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文