簡體   English   中英

如何在 MarkLogic xquery 中獲取具有特定值的特定記錄的計數

[英]How to get count of a certain record with a specific value in MarkLogic xquery

我正在嘗試計算給定條件下的記錄數。

計算輔助價格大於 1000 的集合中所有文檔中輔助價格的數量。

我正在為此嘗試下面的 XQuery,它給了我以下響應:

在 9007.0781 毫秒內返回 532 個項目的序列。 (-361.0691 毫秒,與之前的運行相比)

並隨之在所有 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))

結構稍有不妥。

參考: https ://www.w3schools.com/xml/xquery_flwor.asp

嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM