Treating SQL Results
Monday, 16 November 2015 · 2 messages
DK
Hello Ana,
this is actually very conveniently done using group by (you can see some more examples of group by in our documentation at docs.basex.org). Should look something like this:
for $row in //row
let $author := $row/column[@name = "NOMECOMPLETO"]
group by $author
return $author || ":" || string-join(($row/column[@name = "TITULO"]), ", ")Cheers
Dirk
Quoted text · Ana Victória Ladeira · 50 lines
On 11/16/2015 12:09 PM, Ana Victória Ladeira wrote: > Good morning. > > I have an XML file of the following format: > > <?xml version="1.0" encoding="UTF-8"?> > <resultsets> > <resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > <row> > <column name="TITULO">A Adequação de Sistemas Baseados em > Casos no Sequenciamento Inteligente de Ações</column> > <column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column> > </row> > <row> > <column name="TITULO">Sistemas Distribuídos Inteligentes</column> > <column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column> > </row> > <row> > <column name="TITULO">Uma Arquitetura para Planejamento > Inteligente</column> > <column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column> > </row> > <row> > <column name="TITULO">Navegação de robôs móveis com Lógica > Paracpmsistente Anotada e método de Campos Potenciais</column> > <column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column> > </row> > <row> > <column name="TITULO">Adaptation in a Traffic Control > System</column> > <column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column> > </row> > ... > > > > The file contains titles for articles and their authors.. > > I was asked to develop a query that returns the author's name followed > by the titles of all of its articles, so the result would be something > like this: > > <Author1>:<Article1>, <Article2>, <Article3>... > <Author2>:<Article1>, <Article2>... > ... > > > Any ideas on how can I do it? > > Thank you in advance.
--
Dirk Kirsten, BaseX GmbH, http://basexgmbh.de
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
AL
Ana Victória Ladeira16 Nov 2015 13:09 #
Good morning.
I have an XML file of the following format:
<?xml version="1.0" encoding="UTF-8"?>
<resultsets>
<resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<column name="TITULO">A Adequação de Sistemas Baseados em Casos no
Sequenciamento Inteligente de Ações</column>
<column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column>
</row>
<row>
<column name="TITULO">Sistemas Distribuídos Inteligentes</column>
<column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column>
</row>
<row>
<column name="TITULO">Uma Arquitetura para Planejamento
Inteligente</column>
<column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column>
</row>
<row>
<column name="TITULO">Navegação de robôs móveis com Lógica
Paracpmsistente Anotada e método de Campos Potenciais</column>
<column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column>
</row>
<row>
<column name="TITULO">Adaptation in a Traffic Control
System</column>
<column name="NOMECOMPLETO">José Pacheco de Almeida Prado</column>
</row>
...The file contains titles for articles and their authors..
I was asked to develop a query that returns the author's name followed by the titles of all of its articles, so the result would be something like this:
<Author1>:<Article1>, <Article2>, <Article3>...
<Author2>:<Article1>, <Article2>...
...Any ideas on how can I do it?
Thank you in advance.
Written for BaseX 8.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery