我的 table 是
Product(maker, model, type)
我只想选择相同类型的类型和制造商,并且模型数大于一个。
示例数据:
maker model type
-------------------------------------
A 123 computer
B 234 laptop
B 345 laptop
C 456 printer
C 543 PC
上述样本数据的答案是B和笔记本电脑,因为厂商B只生产笔记本电脑,而且不止一种型号。它不是厂商A,因为即使他生产相同型号的产品,他也只有一种型号。
最佳答案
这很简单。您正在寻找记录数 > 1 且不同类型数 = 1 的制造商:
select maker
from product
group by maker
having count(distinct type) = 1 and count(*) > 1;
关于mysql - 比较同一列同一表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21947235/