Hi Abeshek, First off, I am not totally sure what you mean by "summation value of one field", but I am guessing you mean to sum up all of the value elements under your content element. To start, the naive way to do this is to just do a flowr with an order by, something like this:
xquery version "1.0-ml"; let $node := <content> <id>C1</id> <metadata> <country>USA</country> <value>200</value> </metadata> <metadata> <country>CAN</country> <value>400</value> </metadata> <metadata> <country>AUS</country> <value>300</value> </metadata> </content> let $node2 := <content> <id>C1</id> <metadata> <country>USA</country> <value>200</value> </metadata> <metadata> <country>CAN</country> <value>400</value> </metadata> <metadata> <country>AUS</country> <value>500</value> </metadata> </content> for $x in ($node, $node2) order by fn:sum(fn:data($x//value)) descending return $x Now that might give an expanded tree cache error, not sure, depends on how much memory you have. Now if that is not fast enough (or fills up the cache), then you can try to create another element that calculates the sum of each value, then put a numeric typed range index on that element, and then the order by will be fast if you take a subset of it. Something like: (for $x in $nodes order by $x/sum-of-values return $x)[1 to 10] So there are a few places to start. -Danny From: [email protected] [mailto:[email protected]] On Behalf Of Abhishek53 S Sent: Thursday, May 23, 2013 10:54 AM To: MarkLogic Developer Discussion Subject: [MarkLogic Dev General] Sorting on aggregation in ML4.2-7 Importance: High Hi All, I need to do some sorting over summation value of one field in MarkLogic 4.2-7. Below is the way our content is organized and the sorting is required over sum of all value tag over 1.5 million document Please advise!!! <content> <id>C1</id> <metadata> <country>USA</country> <value>200</value> </metadata> <metadata> <country>CAN</country> <value>400</value> </metadata> <metadata> <country>AUS</country> <value>300</value> </metadata> </content> Abhishek Srivastav Tata Consultancy Services Cell:- +91-9883389968 Mailto: [email protected]<mailto:[email protected]> Website: http://www.tcs.com<http://www.tcs.com/> ____________________________________________ Experience certainty. IT Services Business Solutions Consulting ____________________________________________ =====-----=====-----===== Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
