Xml XQuery分组
什么样的XQuery将产生以下输出?给定以下XML XML-Xml XQuery分组,xml,xquery,Xml,Xquery,什么样的XQuery将产生以下输出?给定以下XML XML- <build id="b0"> <dept>IE</dept> <dept>EE</dept> <name>alpha</name> <type>lib</type> <year>1000</year> </build> <build id="b1"&
<build id="b0">
<dept>IE</dept>
<dept>EE</dept>
<name>alpha</name>
<type>lib</type>
<year>1000</year>
</build>
<build id="b1">
<dept>IE</dept>
<name>beta</name>
<type>teach</type>
<type>lib</type>
<year>1000</year>
</build>
预期产量
<group dept="EE" count="1"/>
<group dept="IE" count="2"/>
按部门分组并打印其计数,其中年份为1000,给出以下更正的input.xml 可以使用此XQuery表达式/文件
let $file := doc("a.xml")
for $cur in distinct-values($file/root/build[year=1000]/dept)
order by $cur
return <group dept="{$cur}" count="{count($file/root/build/dept[. = $cur])}" />
要获得以下所需的输出:
<?xml version="1.0" encoding="UTF-8"?>
<group dept="EE" count="1"/>
<group dept="IE" count="2"/>
<?xml version="1.0" encoding="UTF-8"?>
<group dept="EE" count="1"/>
<group dept="IE" count="2"/>