我有一些表ignore
,其中col ignored_entry_ids
包含整数数组。例如:
id ignored_entry_ids
1 {1,4,6}
2 {6,8,11}
3 {5,6,7}
如何选择阵列中每行中存在的数字? (考试中有6个)
答案 0 :(得分:3)
如果你的数字在数组中是唯一的,你可以做这样的事情,不要认为没有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)