XQuery/XPath LIMIT a sum -
i new xquery. need limit 1 in xquery i'm having trouble.
i trying find out winner of tournament finding each players scores , summing scores total scores. sort in descending order , try limit total score, having problems trying limit in xquery.
here wanting top score have tried use subsequence($sequence, $starting-item, $number-of-items) , [position()] seems not working.
for $pair_ids in distinct-values(fn:doc("tourny.xml")/competition[@date = "2012-12-12"]/tennis/partner/@pair_id) let $total_scores := sum(fn:doc("tourny.xml")/competition[@date = "2012-12-12"]/tennis/partner[@pair_id = $pair_ids]/@score) order $total_scores descending return $total_scores the output giving me:
$total_scores: 34 11 20 how can limit result 34 highest score?
you can use fn:max() function follow:
fn:max( $pair_ids in distinct-values(fn:doc("tourny.xml")/competition[@date = "2012-12-12"]/tennis/partner/@pair_id) let $total_scores := sum(fn:doc("tourny.xml")/competition[@date = "2012-12-12"]/tennis/partner[@pair_id = $pair_ids]/@score) order $total_scores descending return $total_scores )
Comments
Post a Comment