我在尝试比较和计算同一节点的属性时遇到了问题,例如,我需要过滤在同一天运行多次的医生。我的例子是xml:
<ops>
<med_operation pac="p1" doctor="David" date="2017-01-01" />
<med_operation pac="p2" doctor="David" date="2017-01-01" />
<med_operation pac="p3" doctor="Ana" date="2017-01-02" />
</ops>
我只能展示&#34; David&#34;是唯一一个在同一天完成两项操作的人。我得到了这个糟糕的查询
let $m := distinct-values(
let $dates := //med_operation/@date
for $d in $dates
let $ope := //med_operation[@date=$d]
let $c := count(//med_operation[@date=$d])
for $y in (1 to $c)
where ($ope[$y]/@date) = ($ope[$y+1]/@date) and $c > 1
return distinct-values($ope/@doctor)
)
return $m
提前致谢并抱歉我的英文
答案 0 :(得分:1)
在XQuery 3.0中,使用:
for $o in //med_operation
group by $doc := $o/@doctor, $date := $o/@date
where count($o) gt 1
return $doc