分组和总结价值观

时间:2012-12-11 10:10:28

标签: sql-server-2000

找出只生产相同型号型号的制造商,这些型号的数量超过1个。

maker   model   type
 A      1232    PC
 A      1233    PC
 A      1276    Printer
 A      1298    Laptop
 A      1401    Printer
 A      1408    Printer
 A      1752    Laptop
 B      1121    PC
 B      1750    Laptop
 C      1321    Laptop
 D      1288    Printer
 D      1433    Printer
 E      1260    PC
 E      1434    Printer
 E      2112    PC
 E      2113    PC

结果应为

 Model  Type   
  D      Printer 

我试过

   Select maker,type from Product
   Group by maker ,type 
   Having count(*)>1

上面的查询给了我的模型数量超过一个的制造商。但是我无法找到只生成相同类型的模型。请帮助

1 个答案:

答案 0 :(得分:2)

Select Distinct Maker, Type From Product
 Where Maker In (Select Maker From Product 
                  Group By Maker 
                 Having Count(Distinct Type) = 1 
                    And Count(Distinct Model) > 1)