0

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.

2
  • 1
    I'm tempted to flag this as a duplicate of this question. Commented Oct 10, 2016 at 11:59
  • Agreed - an almost exact duplicate. The other question didn't need the join to retrieve the "name" associated with the id, but that is a separate and different kind of question (vs. the list aggregation question which is the main topic). Commented Oct 10, 2016 at 12:04

1 Answer 1

2
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.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.