473,388 Members | 1,234 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Simple group by with Xquery

Hello,

I am newbie in Xquery and i would like to do a simple group by date and
ID.

so a piece of my xml file.
<Authors>
<Author>
<ID>1</ID>
<Date>30.07.2000</Date>
<NTS>56</NTS>
</Author>
<Author>
<ID>1</ID>
<Date>30.06.2000</Date>
<AI>0.00707</AI>
</Author>
<Author>
<ID>1</ID>
<Date>31.07.2000</Date>
<AI>0.00633</AI>
</Author>
<ID>1</ID>
<Date>31.05.2000</Date>
<TVS>2.33</TVS>
</Author>
<ID>1</ID>
<Date>30.06.2000</Date>
<TVS>2.54</TVS>
</Author>
<ID>1</ID>
<Date>31.07.2000</Date>
<TVS>2.46</TVS>
</Author>
....
</Authors>

I would like to group by date and author ID have the TVS, AI and NTS
for every date instead of having seperate records for each date

For example:

<Author>
<ID>1</ID>
<Date>30.07.2000</Date>
<NTS>56</NTS>
<AI>0.00633</AI>
<TVS>2.46</TVS></Author>

I tried to do several codes without success. Any suggestion for this
problem?

Ina

Jul 31 '06 #1
1 1488
For info this my xquey stuff

<TEST>
{
for $i in doc("authors.xml")//Info/Auhors/Author
for $date in $i/Date
let $nts:= fn:sum($i/NTS)
let $ai := fn:sum($i/AI)
let $tvs := fn:sum($i/TVS)

return
<Test>
{ $i/ID }
{ $date }
<NTS>{ $nts }</NTS>
<AI>{ $ai }</AI>
<TVS>{ $tvs }</TVS>
</Test>
}
</TEST>

I do no know how to do that in sql

select Date, ID, sum(isnull(NTS,0)) NTS, sum( isnull(AI,0)) AI,
sum(isnull(TVS,0) TVS
from Author
group by Date, ID

in******@gmail.com wrote:
Hello,

I am newbie in Xquery and i would like to do a simple group by date and
ID.

so a piece of my xml file.
<Authors>
<Author>
<ID>1</ID>
<Date>30.07.2000</Date>
<NTS>56</NTS>
</Author>
<Author>
<ID>1</ID>
<Date>30.06.2000</Date>
<AI>0.00707</AI>
</Author>
<Author>
<ID>1</ID>
<Date>31.07.2000</Date>
<AI>0.00633</AI>
</Author>
<ID>1</ID>
<Date>31.05.2000</Date>
<TVS>2.33</TVS>
</Author>
<ID>1</ID>
<Date>30.06.2000</Date>
<TVS>2.54</TVS>
</Author>
<ID>1</ID>
<Date>31.07.2000</Date>
<TVS>2.46</TVS>
</Author>
...
</Authors>

I would like to group by date and author ID have the TVS, AI and NTS
for every date instead of having seperate records for each date

For example:

<Author>
<ID>1</ID>
<Date>30.07.2000</Date>
<NTS>56</NTS>
<AI>0.00633</AI>
<TVS>2.46</TVS></Author>

I tried to do several codes without success. Any suggestion for this
problem?

Ina
Jul 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Felix Naumann | last post by:
Hi, I am looking for a Java API to represent/generate XQueries. I would imagine it has a class XQuery.java and other classes such as FLWR.java, ORDER.java etc. and one should be able to add...
2
by: Tom Corcoran | last post by:
I am working to ease updating of a html page by transforming 2 xml files. I was going to use xslt for this and had bought 2 unopened books, wrox xslt and o'reilly's xslt cookbook. But am now...
0
by: Betty Harvey | last post by:
The next meeting of the XML Users Group will be held on Wednesday, March 16, 2005 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting...
0
by: Tony Lavinio | last post by:
Dear comp.text.xml community, Microsoft recently announced that they are dropping XQuery from their next release of the .NET Framework, 2.0 (Whidbey). Since Microsoft ships .NET Framework only...
2
by: Daniel | last post by:
update/insert with microsoft.xml.xquery(.net2.0beta) can anyone provide an example of how to update/insert with microsoft.xml.xquery?
4
by: Suma | last post by:
I dont know xquery , so i was thinking someone in the forum will help me out with this easy question Suppose I have an instance document given below <Root> <Author Name='Alice' NumberOfBooks =...
6
by: Armel Asselin | last post by:
Hello, I'm searching for a simple command line tool to manipulate XML files. The idea would be commands such as that: xmanip-tool set /document/xpath/@name="value" remove //wrong-nodes add...
0
by: Betty Harvey | last post by:
The next meeting of the XML Users Group will be held on Wednesday, March 21, 2006 at the American Geophysical Union (AGU) at 2000 Florida Avenue, N.W., Washington, DC 20009-1277. The meeting starts...
2
by: jehugaleahsa | last post by:
Hello: I have an XML file that contains records with a Date attribute. I would like to group all the records together with a particular date, so that I can later iterate over the different dates...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.