expresing grouping in W3c XQuery?

Is it possible to express functionality of group by statement known from Sql? If it is possible please provide some examples.

There’s no direct equivalent to group-by in the current XQuery draft, though there is still a possibility it will get in before version 1.0 is finalized.

Meanwhile you effectively have to hand-code it using the xf:distinct-nodes and xf:distinct-values functions.

Michael Kay

Can you post a simple example of XQuery code
that would utilize xf:distinct-values and function as a ‘GROUP BY’ statement?

The spec is still fluid in this area, and I haven’t checked exactly what’s implemented in QuiP or in Tamino 4.1, but the following gives the idea:

for $i in distinct-values(//employee/deparment/name)
return

{ for $e in //employee
where $e/department/name = $i
return $e
}


I hope this helps!

Michael Kay