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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 query help!!

Author  Topic 

uday1149
Starting Member

4 Posts

Posted - 2007-11-20 : 06:43:19
The database scheme consists of four relations:

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::For Product table, receive result set in the form of a table with columns: maker, pc, laptop, and
printer.
For each maker, this table must include "yes" if a maker has products of corresponding type or "no" otherwise.
In the first case (yes), specify in brackets (without spaces) the quantity of available distinct models of corresponding type (i.e. being in PC, Laptop, and Printer tables).

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-20 : 07:00:07
Try Books Online.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-11-20 : 07:07:54
This should provide you with expected result :-

SELECT p.maker,
CASE WHEN Count(pc.model)> 0 then 'Yes('+CAST(Count(pc.model) AS varchar(2))+')'
ELSE 'No'
END as 'pc',
CASE WHEN Count(l.model)> 0 then 'Yes('+CAST(Count(l.model) AS varchar(2))+')'
ELSE 'No'
END as 'laptop',
CASE WHEN Count(pr.model)> 0 then 'Yes('+CAST(Count(pr.model) AS varchar(2))+')'
ELSE 'No'
END as 'printer'
FROM Product p
LEFT OUTER JOIN PC pc
ON pc.model=p.model
LEFT OUTER JOIN laptop l
ON l.model=p.model
LEFT OUTER JOIN Printer pr
ON pr.model=p.model
GROUP BY p.maker
Go to Top of Page

georgev
Posting Yak Master

122 Posts

Posted - 2007-11-20 : 08:57:29
You learn nothing by copy pasting.


George
<3Engaged!
Go to Top of Page
   

- Advertisement -