I need to sum up the average price of specific product categories, currently i have managed to merge the same category types and count them, now i need to sum up all the prices from the different categories (currently i have selected all prices in my query)
for example: if there are 5 Products of Category A i need to select those 5 prices and sum them up.
Query:
let $hk := doc('http://etutor.dke.uni-linz.ac.at/etutor/XML?id=1')/handelskette/produkte/produkt
for $x in distinct-values($hk/kategorie)
let $c := count($hk[kategorie eq $x])
let $a:= sum($hk/ekPreis)
return <kategorie kname="{$x}">
<anzahl>{$c}</anzahl>
<avgEkPreis>{$a div $c}</avgEkPreis>
</kategorie>
XML:
<handelskette>
<produkte>
<produkt ean="0-666-4567-2-22">
<bezeichnung>Autoschampoo</bezeichnung>
<kategorie>Pflege</kategorie>
<ekPreis>35</ekPreis>
<listPreis>69</listPreis>
</produkt>
<produkt ean="0-777-4997-2-43">
<bezeichnung>Glanzpolitur</bezeichnung>
<kategorie>Pflege</kategorie>
<ekPreis>70</ekPreis>
<listPreis>119</listPreis>
</produkt>
<produkt ean="1-4444-652-8-88">
<bezeichnung>CD-Wechsler</bezeichnung>
<kategorie>Audio</kategorie>
<ekPreis>2345</ekPreis>
<listPreis>3999</listPreis>
</produkt>
</produkte>
</handelskette>
I would be very grateful for any help