仅供参考,初学者,望多交流。
with s1 as
(select servid, count(distinct t.type) as p_count
from product t
where t.type != 1
group by servid)
select *
from servst s
where s.id in (select servid from s1 where s1.p_count between 1 and 3)
and exists (select 1
from product p
where s.id = p.servid
and p.type = 1)