[xquery-talk] group by queries - a more efficient approach

Jason Hunter jhunter at servlets.com
Thu Jul 31 21:58:53 PDT 2003


> for $s in distinct-values($this/mydata/book/subject)
> return
>       <books-by-subject>
>       {
>             for $book in $this/mydata/book[subject/text() = $s/text()]
>                   return
>                         <book>
>                               <name>{$book/name}</name>
>                               <subject>{$book/subject}</subject>
>                         </book>
>       }
>       </books-by-subject>

I suspect something like this would work.  I haven't run it or anything. 
  Basically you can remove the /text() node tests and can return the 
book nodes directly without needing a FLWOR.

for $s in distinct-values($this/mydata/book/subject)
return
       <books-by-subject>
       {
             $this/mydata/book[subject = $s]
       }
       </books-by-subject>

-jh-




More information about the talk mailing list