我有表foo(id INTEGER,值VARCHAR []):
Id / Values
1 / A,B,C
2 / A,C
我想编写一个查询,它只返回所有记录中通用值数组中的元素。
所以对于上面我想得到A,C
任何想法?谢谢!
答案 0 :(得分:1)
with t (id, values) as ( values
(1, '{A,B,C}'::varchar[]),
(2, '{A,C}')
)
select v
from
t
cross join lateral
unnest(values) v(v)
group by v
having count(*) = (select count(*) from t)
;
v
---
C
A