PostgreSQL: select all types that have an entry corresponding to all entries in another table

拟墨画扇 提交于 2019-12-08 05:03:30

Count the number of producers per type and compare with the total number of producers:

select type
from skis
group by type
having count(distinct producer) = (select count(*) from producers);

Is it work for you?

select s.type
from
(
select type,
       count(distinct producer) amount_producers_for_type
 from skis
 group by type
 ) s
 inner join (
             select count(distinct name) number_of_producers
             from producers
             ) t
 on t.number_of_producers = s.amount_producers_for_type
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!