-1
我的子查詢不會產生正面影響。請幫忙。列元素是字符串,用逗號分隔;Postgresql子查詢語句中的字符串文本
select id, title, elements, (
select string_agg(distinct street, ',')
from locations
where elementnames in (replace(quote_nullable(elements),',',''','''))
) as buildings
from events ;
id | title | elements | buildings
-----------+-------+---------------------+----------
124003 | alpha | NYCID005 |
000111 | beta | NYCID222 |
20| gamma | NYCID201,NYCID193 |
102036 | sigma | NYCID202,NYCID191 |
(4 rows)
請不要在一列中存儲逗號分隔值。你的問題是不好的設計的直接結果 –
我可以改變架構,請給我一個例子如何改變它。 – elektromonter