0

我想知道是否有一种方法可以在查询的一列中获取子查询的多个结果......像这样:

otherid | resultsFromsomeData
1       | 1,2,3   
2       | 1,5  
3       | No Data   

我正在尝试这样的事情:

select o.otherID, 
CASE WHEN (select otherID from someData where someid=o.otherID)>1 THEN
       ''||(select otherID from someData where someid=o.otherID)||'' /*here I am*/
   WHEN (select otherID from someData where someid=o.otherID)<1 THEN
       'No Data'
   END 
as resultsFromsomeData
from OtherData o


4

1 回答 1

0

看起来像一个简单的加入和分组:

select o.other_id, 
       coalesce(string_agg(sd.other_id, ','), 'No data') as results_from_some_data
from other_data o
  join some_data d on o.other_id = d.someid
group by o.other_id;
于 2020-05-12T20:26:57.337 回答