It is OK to run a bunch of loops. You will have to do that to get a group by-like result.
As Geert suggested, substitute in a cts:element-values call for the distinct-values. Give it a try, run it in the profiler, and see how long it takes. -Danny From: [email protected] [mailto:[email protected]] On Behalf Of helen chen Sent: Wednesday, November 17, 2010 9:59 AM To: General Mark Logic Developer Discussion Subject: Re: [MarkLogic Dev General] how to do query like group and max in sql Hi Tim, actually <coden> is just a tag in the article xml, but it is unique, volume and issue are also unique in the article. We have a lot of articles for each issue, 20-30 issues for each volume, may be over 100 volumes for each coden, The result I want to get should not be big because I only want one element for each coden. I see the loop, I feel it is too many loops to run. Thanks, Helen On Nov 17, 2010, at 11:26 AM, Tim Meagher wrote: Hi Helen, I guess the first thing I'd want to know is how big the resulting document is going to be and hw you want to store it, i.e. do you want to fragment a large document by coden or perhaps have a separate document for each unique coden. Secondly I would probably approach this as a transform, doing something like this: let $distinct-codens := distinct-values(~/article/coden/text()) return for $coden in $distinct-codens return element coden { for $article in ~/article where $article/coden/text() eq $coden return ( $article/volume, $article/issue, ... ) } Hope this helps! I hope to see some more robust ideas come out. Tim Meagher _______________________________________________ General mailing list [email protected]<mailto:[email protected]> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
