SELECT ci.ciname AS "名称", cit.typename AS "配置项类型", sdorg.name AS "地点", (SELECT Array_to_string(Array_agg(Concat(rel.relationship, ' ', ci2.ciname)), ', ')
FROM cirelationships AS cirel
LEFT JOIN ci AS ci2
ON ci2.ciid = cirel.ciid2
LEFT JOIN relationshiptype AS rel
ON rel.relationshiptypeid = cirel.relationshiptypeid
WHERE cirel.ciid = ci.ciid) AS "关系详情"
FROM ci
left join citype as cit on ci.citypeid=cit.typeid
left join SDOrganization as sdorg on sdorg.org_id=ci.siteid
WHERE ciid IN (SELECT ciid FROM cirelationships) and cit.typename like '%工作站%' and sdorg.name like '%上海%'