我有一个如下所示的 xml 文件,我想对 toyID 进行分组并获得该玩具已售出的总和。并按销售额最高的 toyID 排序。但是我编写的代码能够汇总玩具销售量,但是按玩具销售量最高的顺序不起作用。我能知道我做错了哪一部分吗?
ToySale.XML
<toySale companyID="1" toyID="11" >
<amount>15</amount>
</toySale>
<toySale companyID="3" toyID="11" >
<amount>12</amount>
</toySale>
<toySale companyID="1" toyID="22" >
<amount>3</amount>
</toySale>
<toySale companyID="2" toyID="33" >
<amount>7</amount>
</toySale>
下面是我写的代码:
for $t in distinct-values(ToySale.xml")//@toyID)
return <toyID>
toyID : {$t}
<totalSale>{sum(for $sum in (ToySale.xml")//toySale
order by $sum/@toyID/../amount
where $t=$sum/@toyID
return $sum/@productID/../amount) }
</totalSale
</toyID>