1

我有一些表ignorecolignored_entry_ids包含整数数组。例如:

id     ignored_entry_ids
1      {1,4,6}
2      {6,8,11}
3      {5,6,7}

如何使用数组选择每一行中存在的数字?(例如 6 个)

4

1 回答 1

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)

sql fiddle demo

如果数字不是唯一的,请添加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)
于 2013-08-29T11:05:47.740 回答