2
我有3個XML文件,如下所示,我希望將所有這3個文檔連接在一起,以便我可以執行彙總功能以查明特定分類名稱的銷售量。但似乎我寫的代碼有問題。請指導我如何在三個文件上執行彙總功能。分組彙總
ClassDescription.XML
<classification name="Electronic">
<Description>electronic devices that requires electric</Description>
</classification>
<classification name="SoftToy">
<Description>Fluffy toys that kids like</Description>
</classification>
ToyClassification.XML
<toy toyID="11">
<name>Doll</name>
<classification>SoftToy</classification>
</toy>
<toy toyID="22">
<name>Xbox</name>
<classification>Electronic</classification>
</toy>
<toy toyID="33">
<name>PS3</name>
<classification>Electronic</classification>
</toy>
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>
<ClassList>
<classification name="SoftToy">
<totalSale>4</totalSale>
</classification>
<classification name="Electronic">
<totalSale>3</totalSale>
</classification>
</ClassList>
下面是我有的代碼,但似乎它不工作。可能我知道什麼是正確的xquery這個工作?
for $class in (ClassDescription.XML)//classification/@name
for $toyClass in (ToyClassification.XML)//toy/@toyID
for $sale in (ToySale.XML)//toySale/@toyID
let $sum := (ToySale.XML)//toySale[@toyID = $toyClass]
where $sale=$toyClass and $class=$toyClass/../name
order by sum($sum/amount)
return <ClassList>{$class}</ClassList>
嗨dimitre,已經試過你的查詢,是的,它運作良好。再次學習新的東西。謝謝 – setiasetia