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.
Author |
Topic |
kwacz23
Starting Member
44 Posts |
Posted - 2013-11-24 : 08:48:30
|
Please help me with belowFind out makers who produce only the models of the same type, and the number of those models exceeds 1.Deduce: maker, typeDb consist below tables. Key is model.The database scheme consists of four tables: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)I tried below but iam geting two resultswith a as (select maker,type,count(*) as number from productgroup by maker,type)select maker,count(*) from agroup by makertable product containmaker model typeA 1232 PCA 1233 PCA 1276 PrinterA 1401 PrinterA 1408 PrinterA 1298 LaptopA 1752 LaptopB 1121 PCB 1750 LaptopC 1321 LaptopD 1433 PrinterD 1288 PrinterE 1260 PCE 1434 PrinterE 2113 PCE 2112 PC |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 00:40:22
|
[code]SELECT makerFROM tableGROUP BY makerHAVING MIN(type) = MAX(type)AND MIN(model) <> MAX(model)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-11-25 : 00:40:28
|
select maker,type,count(*) as number from productgroup by maker,typeHAVING count(DISTINCT model ) >1--Chandu |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-11-25 : 00:43:06
|
quote: Originally posted by bandi select maker,type,count(*) as number from productgroup by maker,typeHAVING count(DISTINCT model ) >1--Chandu
I cant see how this will ensure the maker has only one type associated to it.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-11-25 : 01:14:20
|
quote: Originally posted by visakh16
quote: Originally posted by bandi select maker,count(*) as number from productgroup by makerHAVING count(DISTINCT model ) >1 AND count(DISTINCT type)=1--Chandu
I cant see how this will ensure the maker has only one type associated to it.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
--Chandu |
|
|
|
|
|
|
|