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

Dmitri.Colebatch at toyota.com.au Dmitri.Colebatch at toyota.com.au
Fri Aug 1 14:30:04 PDT 2003


hey again,

hope that I'm not imposing too much on this list... definately making
progress, would like some thoughts on group by style queries...  Suppose I
have this document:

<mydata>
      <book>
            <name>Struts</name>
            <subject>Java</subject>
      </book>
      <book>
            <name>EJB</name>
            <subject>Java</subject>
      </book>
      <book>
            <name>Patterns</name>
            <subject>Design</subject>
      </book>
      <book>
            <name>Refactoring</name>
            <subject>Design</subject>
      </book>
      <book>
            <name>XSLT</name>
            <subject>XML</subject>
      </book>
</mydata>

and I want to create multiple documents (nodes), grouped by subject - I
couldn't find any mention of any support for group by queries, so I've used
the following:

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>

which works, but "feels" like there might be a better approach...  has
anyone here done this sort of thing before?  any ideas?

the reason I'm doing this is that I'm receiving a document in batch mode
that has address information contained in its items - each item might go to
a different destination, so I want to "re-batch" the document into smaller
documents to be sent to their final destination.

cheers, and thanks again
dim

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                               DISCLAIMER
* This email and any attachment may contain confidential information.
  If you are not the intended recipient you are not authorised to copy
  or disclose all or any part of it without the prior written consent
  of Toyota.
* Opinions expressed in this email and any attachment are those of the
  sender and not necessarily the opinions of Toyota.
* Please scan this email and any attachment for viruses.  Toyota does
  not accept any responsibility for problems caused by viruses, whether
  it is Toyota's fault or not.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -




More information about the talk mailing list