Search item result in same line separated by comma

Asked

Viewed 197 times

0

I have a select that returns the risks (work safety) in several lines, I would like the item "T4.RIS_RISCO" to appear in a single line separated by comma, can anyone help me?? 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

1 answer

1

You can use the 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 "off the list")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.