简体   繁体   English

MarkLogic 光学查询中的错误 - 获取模板视图文档中记录出现的百分比

[英]Error in MarkLogic Optic Query - to get percentage of occurrence of a record in a template view document

I am trying to find the percentage of a certain record based on a condition to the total no of that record.我正在尝试根据条件查找某个记录占该记录总数的百分比。 I am using optic query to get the result.我正在使用光学查询来获得结果。

To be specific on the requirement:具体要求:

Give a percentage of a certain record, when there is a condition, with the total number of that record available in the template view.给出某个记录的百分比,当有条件时,模板视图中可用该记录的总数。

Here is my optic query which I am trying -这是我正在尝试的光学查询-

 xquery version "1.0-ml"; import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy"; import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy"; import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy"; declare option xdmp:mapping "false"; let $view:= op:from-view("GTM2_Shipment", "Shipment_View") let $Ancillary_QuotePrice:= op:view-col("Shipment_View", "Ancillary_QuotePrice") return $view => op:group-by((),(op:count("TotcountOfColumn", $Ancillary_QuotePrice),op:count("percentageCount", $Ancillary_QuotePrice))) => op:select( op:as("CountOnCond", op:where(op:and(( op:gt($Ancillary_QuotePrice, 0),op:gt(ofn:format-dateTime(op:col('BookingCreateDt'), '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]'))) )) ) ), op:as("Percentage",op:divide(op:col("CountOnCond"),op:col("TotcountOfColumn"))) ) => op:result()

It gives me this error -它给了我这个错误-

 1.0-ml] XDMP-TOOFEWARGS: (err:XPST0017) op:where(op:and((op:gt($countOfColumn, 0), op:gt(ofn:format-dateTime(op:col("BookingCreateDt"), "[Y0001]-[M01]-[D01]"), osql:dateadd("month", -6, ofn:format-dateTime(fn:current-dateTime(), "[Y0001]-[M01]-[D01]")))))) -- Too few args, expected 2 but got 1

Also please check if my query logic is correct or not.另外请检查我的查询逻辑是否正确。

 xquery version "1.0-ml"; import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy"; import module namespace ofn="http://marklogic.com/optic/expression/fn" at "/MarkLogic/optic/optic-fn.xqy"; import module namespace osql="http://marklogic.com/optic/expression/sql" at "/MarkLogic/optic/optic-sql.xqy"; declare option xdmp:mapping "false"; let $view:= op:from-view("GTM2_Shipment", "Shipment_View") let $Var1:= op:view-col("Shipment_View", "Ancillary_QuotePrice") let $Var2:= op:view-col("Shipment_View", "Shipment_Ref") return $view => op:group-by((),(op:count("Var2", $Var2),op:count("Var1", $Var1))) =>op:select(op:as("multiply", op:divide(op:col("Var1"), op:col("Var2")))) =>op:select(op:as("percentageFinal", op:multiply(100, op:col("multiply")))) => op:result()

Above is the straightforward percentage found for Var1 with total of Var2.以上是 Var1 与 Var2 的总和的直接百分比。 I want the condition of the Var1 to be added in the code.我希望将 Var1 的条件添加到代码中。 Where can I add the where condition please.请问哪里可以添加where条件。

op:where() expect the first parameter to be the $plan . op:where()期望第一个参数是$plan Typically, when chaining calls from a plan using => it is set as that first parameter for you, and you are then providing the subsequent parameters starting from the second parameter with what is explicitly set in the function call.通常,当使用=>链接来自计划的调用时,它会为您设置为第一个参数,然后您将从第二个参数开始提供后续参数,并在 function 调用中明确设置。

So, when attempting to apply op:where() as the expression for op:as() to bind to:因此,当尝试应用op:where()作为op:as()绑定到的表达式时:

 op:as("CountOnCond", op:where(op:and(( op:gt($Ancillary_QuotePrice, 0),op:gt(ofn:format-dateTime(op:col('BookingCreateDt'), '[Y0001]-[M01]-[D01]'),osql:dateadd('month',-6, ofn:format-dateTime(fn:current-dateTime(),'[Y0001]-[M01]-[D01]'))) )) )

the op:and() parameter being specified is the one and only parameter being specified, but op:where() has two required parameters.指定的op:and()参数是唯一指定的参数,但op:where()有两个必需参数。

That is why it throws the XDMP-TOOFEWARGS error.这就是它抛出XDMP-TOOFEWARGS错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM