我有一些表ignore
colignored_entry_ids
包含整数数组。例如:
id ignored_entry_ids
1 {1,4,6}
2 {6,8,11}
3 {5,6,7}
如何使用数组选择每一行中存在的数字?(例如 6 个)
我有一些表ignore
colignored_entry_ids
包含整数数组。例如:
id ignored_entry_ids
1 {1,4,6}
2 {6,8,11}
3 {5,6,7}
如何使用数组选择每一行中存在的数字?(例如 6 个)
如果你的数字在数组中是唯一的,你可以做这样的事情,不要认为没有unnest
with cte as (
select id, unnest(ignored_entry_ids) as arr
from ign
)
select arr
from cte
group by arr
having count(*) = (select count(*) from ign)
如果数字不是唯一的,请添加distinct
:
with cte as (
select distinct id, unnest(ignored_entry_ids) as arr
from ign
)
select arr
from cte
group by arr
having count(*) = (select count(*) from ign)