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 |
|
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. |
 |
|
|
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 pLEFT OUTER JOIN PC pcON pc.model=p.modelLEFT OUTER JOIN laptop lON l.model=p.modelLEFT OUTER JOIN Printer prON pr.model=p.modelGROUP BY p.maker |
 |
|
|
georgev
Posting Yak Master
122 Posts |
Posted - 2007-11-20 : 08:57:29
|
You learn nothing by copy pasting. George<3Engaged! |
 |
|
|
|
|
|
|
|