0

Does someone knows how to get that result bellow ?

There is a sceneario

ID          DATE        Description
00041454707 27/07/17    Hospital Sugisawa Pronto Atendimento
00041454707 27/07/17    Hospital Pequeno Príncipe
00041454707 28/07/17    Hospital Sugisawa Pronto Atendimento

Result expected :

ID          DATE        Description
00041454707 27/07/17    Hospital Sugisawa Pronto Atendimento | Hospital Pequeno Príncipe
00041454707 28/07/17    Hospital Sugisawa Pronto Atendimento

Look at result ,I've grouped the first and second one , which has same date 27/07/17 , and concatened in Description field .

I dunno have much background in DB2 .

DB2 V11.1

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Luiz
  • 141
  • 2
  • 14

1 Answers1

1
SELECT id, dateval,
  LISTAGG(descval, ' | ') AS descvals
FROM yourtable
GROUP BY id, dateval

As already mentioned by others here, the trick is done by LISTAGG function. GROUP BY operator collects the rows into a group, and LISTAGG collects the values into a string with the separator specified.