我有一张表“生产”:
|company | Product | Model|
A Printer 1200
B Lap 1100
C PC 1500
C Lap 1300
A Printer 1800
我想找出只生产1种产品的公司, 这些模型的数量超过1个。
我尝试了很多。但我只选择公司产品1类型。
请帮助我。
答案 0 :(得分:0)
试试这个:
Select company from production
group by company
having count(distinct product) = 1
and count(distinct model) > 1
在此处查看演示小提琴http://sqlfiddle.com/#!2/f8a11/3
答案 1 :(得分:0)
select company from product
where company in
(select company from product group by company having count(distinct product)=1)
group by company
having count(distinct model)>1
答案 2 :(得分:0)
select company from production
group by company
having count(distinct model)>1 and count(distinct product)=1