Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Exercise: 14

Author  Topic 

fullypaglot
Starting Member

6 Posts

Posted - 2013-08-08 : 09:24:24
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)

(question which I dont even understand)
Find out makers who produce only the models of the same type, and the number of those models exceeds 1.
Deduce: maker, type

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-08 : 09:38:39
something like


SELECT t.maker,t.type,..other columns if any
FROM Product t
INNER JOIN (SELECT maker,COUNT(model) AS Cnt
FROM Product
GROUP BY maker
HAVING COUNT(DISTINCT type) =1
)t1
On t1.maker = t.maker
WHERE t1.Cnt > 1



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

fullypaglot
Starting Member

6 Posts

Posted - 2013-08-08 : 09:45:50
thanks a lot it works perfectly the only thing which I added was distinct.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-08 : 09:52:42
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -