我使用POSTGRESQL 9.1.3作为后端,VS2010 c#作为前端。 我有两张表如下:
属性
Property_id Property_details
------------------------------
1 abc
2 xyz
言过其实
Claimer_ID First_name Last_Name Property_id
---------------------------------------------
1 aaaa bbbbb 1
2 cccc ddddd 2
3 eeee fffff 1
4 gggg hhhhh 2
我想要关注输出
Property_id Claimers
------------------------------------
1 aaa bbbb,eeee ffff
2 ccc dddd,gggg hhhh
3 (may be more than 2 claimers)
此处claimer是一个列,可能包含1个或多于1个(最多50个)的请求者名称
我该怎么做?
答案 0 :(得分:2)
SELECT a."Property_id",
array_agg(b."First_name" || ' ' || b."Last_Name") AS "Claimers"
FROM Property a
INNER JOIN Claimers b
ON a."Property_id" = b."Property_id"
GROUP BY a."Property_id"