Xquery 如何计算具有相同日期的子项的节点数
下面是Xml结构。我必须清点同一日期的安装情况,并列出它们。因此,我必须按InstallDate查找count并在XQuery中返回,以便在Marklogic查询中使用Xquery 如何计算具有相同日期的子项的节点数,xquery,marklogic,marklogic-9,Xquery,Marklogic,Marklogic 9,下面是Xml结构。我必须清点同一日期的安装情况,并列出它们。因此,我必须按InstallDate查找count并在XQuery中返回,以便在Marklogic查询中使用 <PcDetail> <Installations> <Installation> <Type>pc</Type> <purchased>Y</purchased> <InstallD
<PcDetail>
<Installations>
<Installation>
<Type>pc</Type>
<purchased>Y</purchased>
<InstallDate>2020-10-01T00:00:00:000Z</InstallDate>
</Installation>
<Installation>
<Type>pc</Type>
<purchased>Y</purchased>
<InstallDate>2020-10-01T00:00:00:000Z</InstallDate>
</Installation>
<Installation>
<Type>pc</Type>
<purchased>Y</purchased>
<InstallDate>2020-10-02T00:00:00:000Z</InstallDate>
</Installation>
<Installation>
<Type>pc</Type>
<purchased>Y</purchased>
<InstallDate>2020-10-02T00:00:00:000Z</InstallDate>
</Installation>
<Installation>
<Type>pc</Type>
<purchased>Y</purchased>
<InstallDate>2020-10-02T00:00:00:000Z</InstallDate>
</Installation>
</Installations>
个人计算机
Y
2020-10-01T00:00:00:000Z
个人计算机
Y
2020-10-01T00:00:00:000Z
个人计算机
Y
2020-10-02T00:00:00:000Z
个人计算机
Y
2020-10-02T00:00:00:000Z
个人计算机
Y
2020-10-02T00:00:00:000Z
即使在XQuery 1.0中也非常简单
let $installations := $xml/PcDetail/Installations/Installation
for $date in fn:distinct-values($installations/InstallDate)
let $installationsOnDate := $installations[InstallDate = $date]
let $c := count($installationsOnDate)
return $date || ':' || $c || ':' || string-join($installationsOnDate/type,', ')
即使在XQuery1.0中也非常简单
let $installations := $xml/PcDetail/Installations/Installation
for $date in fn:distinct-values($installations/InstallDate)
let $installationsOnDate := $installations[InstallDate = $date]
let $c := count($installationsOnDate)
return $date || ':' || $c || ':' || string-join($installationsOnDate/type,', ')
如果您希望在MarkLogic server中按日期分组、计数和列出
安装
,请参阅下面的MarkLogic XQuery方言
:
for $d in distinct-values(doc()//InstallDate)
let $i := doc()//Installation[InstallDate = $d]
order by $d
return <Installations Date="{$d}" Count="{count($i)}">
{
for $install in $i
return $install
}</Installations>
如果您希望在MarkLogic server中按日期分组、计数和列出
安装
,请参阅下面的MarkLogic XQuery方言
:
for $d in distinct-values(doc()//InstallDate)
let $i := doc()//Installation[InstallDate = $d]
order by $d
return <Installations Date="{$d}" Count="{count($i)}">
{
for $install in $i
return $install
}</Installations>