Here is the table:
Product(maker, model, type)
The table "Product" includes information about the maker, model number, and type ('PC', 'Laptop', or 'Printer')
Challenge:
Find out makers who produce only the models of the same type, and the number of those models exceeds 1.
What I did:
SELECT maker, type
FROM Product
GROUP BY maker
HAVING COUNT (type) > 1 AND COUNT( DISTINCT type ) = 1
Problem:
Column 'Product.type' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Notes:
In the table, the maker D creates only Printers. So, I want to get:
Maker | Type
D | Printer
If I remove type from the query I get D, which is what I want, but without type. If I include type in GROUP BY clause I get different result.
Question:
How to fix this?
SELECT maker, MIN(type)
FROM product
GROUP BY
maker
HAVING COUNT(DISTINCT type) = 1
AND COUNT(*) > 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With