MySQL JOIN 一对多,用连字符分隔

MySQL JOIN one to many separated by hyphens

我想知道是否可以使用 MySQL:

我有两个 table:

阈值 (table)

-idThreshold(字段) -姓名(字段)

threshold_results (table)

-idThreshold(字段) -idResult(字段)

一个阈值可以有多个结果

我想要一个 SELECT 以这种方式显示每个阈值的结果

示例:

Threshold(column)   idResults(column)
idThreshold1        IdResult1-IdResult2-idResult3
idThreshold2        IdResult1
idThreshold3        IdResult2-idResult3
idThreshold4
idThreshold5        IdResult7

谢谢!

使用GROUP_CONCAT

select t.name, group_concat(distinct r.idResult separator '-') as results
from threshold t
left join threshold_results r on r.idThreshold = t.idThreshold 
group by t.idThreshold, t.name