Search item result on the same line separated by commas

0

I have a select that returns the risks (job security) in several lines, I would like the item "T4.RIS_RISCO" to appear in a single line separated by a comma, can anyone help me ??? I have basic knowledge ...

SELECT 
  T1.ASO_ID,
  T1.RIS_ID,
  T3.RGR_GRUPO,
  T4.RIS_RISCO
FROM
  ASO_RISCOS T1
  INNER JOIN GRUPO_RISCOS T2 ON (T1.RIS_ID = T2.RIS_ID)
  INNER JOIN RISCO_GRUPO T3 ON (T2.RGR_ID = T3.RGR_ID)
  INNER JOIN RISCOS T4 ON (T2.RIS_ID = T4.RIS_ID)
WHERE T1.ASO_ID = :ASO_ID
ORDER BY RGR_GRUPO, RIS_RISCO
    
asked by anonymous 30.10.2018 / 12:22

1 answer

0

You can use list() ::

SELECT T1.ASO_ID, T1.RIS_ID, T3.RGR_GRUPO, LIST(T4.RIS_RISCO, ', ')
FROM
  ASO_RISCOS T1
  INNER JOIN GRUPO_RISCOS T2 ON (T1.RIS_ID = T2.RIS_ID)
  INNER JOIN RISCO_GRUPO T3 ON (T2.RGR_ID = T3.RGR_ID)
  INNER JOIN RISCOS T4 ON (T2.RIS_ID = T4.RIS_ID)
WHERE T1.ASO_ID = :ASO_ID
GROUP BY T1.ASO_ID, T1.RIS_ID, T3.RGR_GRUPO
ORDER BY RGR_GRUPO, RIS_RISCO

(remember to group by fields that are "out of list")

    
30.10.2018 / 12:53