1
我有一些表ignore
与col ignored_entry_ids
包含整数的数组。例如:选择Postgres中所有数组中存在的值
id ignored_entry_ids
1 {1,4,6}
2 {6,8,11}
3 {5,6,7}
如何选择数字,与阵列的每一行中是否存在? (在examle 6)
我有一些表ignore
与col ignored_entry_ids
包含整数的数组。例如:选择Postgres中所有数组中存在的值
id ignored_entry_ids
1 {1,4,6}
2 {6,8,11}
3 {5,6,7}
如何选择数字,与阵列的每一行中是否存在? (在examle 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)
这是很好的解决方法,谢谢! –
究竟是你想要的结果?如果您查询数字5,结果应该是什么? –
结果是所有用户都忽略的enrty_id数组(来自'ignored_entry_ids'列)。换句话说,在'ignored_entry_ids'列中的所有行中都存在^数字。 –