一列中的子查询结果? PostgreSQL
Results of Sub query in one column? Postgresql
我想知道是否有办法在查询的一列中获取子查询的多个结果...
像这样:
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
看起来像一个简单的加入和分组依据:
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;
我想知道是否有办法在查询的一列中获取子查询的多个结果... 像这样:
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
看起来像一个简单的加入和分组依据:
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;