Mr.Gigi
Mr.Gigi

Reputation: 25

Recursive records oracle

I'm currently trying to create a report using SQL Developer.

I have these 2 tables:

PERSONS (IDPerson, NamePerson) PENALTIES (IDPenalty, DatePenalty, Description, IDPerson)

The tables are polulated.

How could I create a table like

THIS

using recursive queries in SQL? or it's there any other solution? Thank you in advance.

Upvotes: 0

Views: 42

Answers (1)

user5683823
user5683823

Reputation:

select   p.nameperson as name, p.idperson as id,
         listagg(to_date(x.datepenalty, 'dd/mm/yyyy') || ' - ' || x.description, '; ')
                                      within group (order by x.datepenalty) as penalties
from     persons p left outer join penalties x
                   on p.idperson = x.idperson
group by p.idperson;

(Not tested - you didn't provide test data.)

Upvotes: 2

Related Questions