Select 多对多关系 table

Select from many to many relations table

鉴于这些表格:

我想查询所有连接套件的场景。

结果:

 **scenario**         **suites**
loginScenario         loginSignup, endToEnd, smoke
  addToCart           shoppingCart, paymentOptions, endToEnd

请将我指向首选的 postgresql select 查询

另外这里的关系是一个(场景)到多个(套房),如果设计不同请指教。

使用连接和字符串聚合:

select 
    sc.description scenario_description, 
    string_agg(su.description, ', ') all_suites_descriptions
from scenario_suit scsu
inner join scenarios sc on sc.scenario_id = scsu.scenario
inner join suites su    on su.suite_id    = scsu.suite
group by sc.scenario_id

我假设 table suites 有一个名为 description 的列,您要显示它。