Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix B Format of Search, Return and Sort Expressions> B.4 Return Expressions

B.4.4 Example Return Expressions used when Aggregating

Some example return expressions are shown below.

Document A

<doc>
  <companyname>fujitsu</companyname>
  <employee position="manager">
    <name>smith</name>
    <id>2000</id>
    <age>30</age>
    <comment></comment>
  </employee>
</doc>

Document B

<doc>
  <companyname>fujitsu</companyname>
  <employee position="chief">
    <name>jones</name>
    <id>1000</id>
    <age>35</age>
    <comment>team leader</comment>
  </employee>
</doc>

Example 1: Example of the avg Function

Return Expression

avg(/doc/employee/age/text())

Sort Expression

/doc/companyname/text()

Result

32.5

Example 2: Example of the count Function that the attribute expression is specified

Return Expression

count(/doc/employee/@position)

Sort Expression

/doc/employee/text()

Result

2

If multiple return items are specified, the value of each return item contained in the result will be separated by the delimiter.

Example 3: Example of Specifying Multiple Return Items

Return Expression

avg(/doc/employee/age/text()),count(/doc/employee/name/text())

Sort Expression

/doc/companyname/text()

Result

32.5,2

If the text node specified with the expression or the attribute node specified with the attribute expression occurs more than once in the same document, only the value of the first text node or the value of attribute node will be used.

Example

In the following example, the text expression '/student/subject/test/score/text()' is passed as an argument to the avg function. In this case, Document A will not be included in the aggregation target, the value of Document B will be treated as 80, and Document C will be 0.

Document A

<student>
  <name>smith</name>
  <subject>
    <subjectname>science</subjectname>
  </subject>
  <name>smith</name>
</student>

Document B

<student>
  <name>jones</name>
  <subject>
    <subjectname>science</subjectname>
    <test>
      <date>2006/01/12</date>
      <score>80</score>
    </test>
    <test>
      <date>2005/12/08/</date>
      <score>70</score>
    </test>
  </subject>
</student>

Document C

<student>
  <name>murphy</name>
  <subject>
    <subjectname>science</subjectname>
    <test>
      <date>2006/01/12</date>
      <score>--</score>
    </test>
  </subject>
</student>

Return expression

avg(/student/subject/test/score/text())

Sort expression

/student/subject/subjectname/text()

Result

40

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006