I am sitting here since three hours trying to figure out how to make a simple group by in XQuery. I really don’t understand why W3C decided not implementing an Groupby into XQuery.
My Sql Statement:
SELECT
wisc_berkeley_tracetime.rID,
wisc_berkeley_tracelist.ip
FROM
wisc_berkeley_tracelist INNER JOIN wisc_berkeley_tracetime
ON wisc_berkeley_tracelist.rID= wisc_berkeley_tracetime.rID
WHERE
(wisc_berkeley_tracetime.dat = '20000801000000')
GROUP by wisc_berkeley_tracelist.ip;
</pre><BR><BR>So this is the exact statement in XQuery just without Group by:<BR><BR><pre class="ip-ubbcode-code-pre">
for $tl in doc("wisc_berkeley_tracelist.xml")/data/row
for $tt in doc("wisc_berkeley_tracetime.xml")/data/row[dat='20000801000000' and rID=$tl/rID]
return
<ROW>
{ $tl/ip }
{ $tt/rID }
</ROW>
But how do I the Group by?
Best Regards
Houman Khorasani University of Wisconsin Platteville
XQuery supports grouping with the aid of the distinct-values() function that is not yet supported with Tamino 4.1. It will however be contained in 4.2. On how to do grouping with distinct-values() please check appendix G2 in the W3C’s XQuery draft, i.e. http://www.w3.org/TR/xquery/#id-grouping.
Actually it really gets hard if I need to groupby within a join.
The xample in W3 Draft doesn’t explain groupby within a join.
SELECT
wisc_berkeley_tracetime.rID,
ip,
min
FROM
wisc_berkeley_tracelist INNER JOIN wisc_berkeley_tracetime
ON wisc_berkeley_tracelist.rID = wisc_berkeley_tracetime.rID
WHERE
(wisc_berkeley_tracetime.ndate = '20000801000000')
GROUP by wisc_berkeley_tracelist.ip;
</pre><BR><BR>This XQuery statement has no ?group by? on ip yet. I am aware of distinct-value but have no idea how to use it in an efficient way on this query.<BR> <BR><pre class="ip-ubbcode-code-pre">
for $wbtl in doc("wisc_berkeley_tracelist.xml")//row,
$wbtt in doc("wisc_berkeley_tracetime.xml")//row[dat = '20000801000000' and rID = $wbtl/rID]
return
<ROW>
{
$wbtt/rID, $wbtl/ip, $wbtt/min
}
</ROW>
Do you have an idea how to do that?
Thanks
Houman Khorasani University of Wisconsin Platteville
let $wbttlist := for $wbtl in doc(“wisc_berkeley_tracelist.xml”)//row return doc(“wisc_berkeley_tracetime.xml”)//row[dat = ‘20000801000000’ and rID = $wbtl/rID] for $ip in distinct-values($wbttlist/ip) return