我有一个列在table1包含以逗号分隔的名称,如a、b、c
<表类>
名称
结果
tbody><<tr>a, d, e a, c, e, f c, d, f, g td 表类>
如果您想要的结果是布尔值,则使用exists(...)
:
update table1 as t1
set result = exists(
select name
from table2
where origin = 'UK'
and name = any(string_to_array(t1.names, ','))
);
在db<>fiddle中测试。
如果您想获得名称,使用string_agg()
:
update table1 as t1
set result = (
select string_agg(name, ',')
from table2
where origin = 'UK'
and name = any(string_to_array(t1.names, ','))
);
,Db<的在小提琴。