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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -