Question

My table is

Product(maker, model, type)

I want to select type and maker of only the same type and also having count of models greater than one.

Sample data:

maker             model         type
-------------------------------------
 A                 123        computer
 B                 234         laptop
 B                 345         laptop
 C                 456         printer
 C                 543           PC

The answer for the above sample data is B and laptop because maker B manufactures only laptops and also more than one model.It is not maker A because even though he manufactures product of same type he has only one model.

Was it helpful?

Solution

That's easy. You are looking for makers with a record count > 1 and a count of distinct types = 1:

select maker
from product
group by maker
having count(distinct type) = 1 and count(*) > 1;

OTHER TIPS

Try this :

SELECT maker 
FROM Product
GROUP BY maker, type
HAVING COUNT(1) > 1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top