SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 i need help with sql exercise.. pls help!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

paulpol87
Starting Member

7 Posts

Posted - 02/03/2012 :  10:11:25  Show Profile  Reply with Quote
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)
The table "Product" includes information about the maker, model number, and type ('PC', 'Laptop', or 'Printer'). It is assumed that model numbers in the Product table are unique for all the makers and product types. Each PC uniquely specifying by a code in the table "PC" is characterized by model (foreign key referencing to Product table), speed (of the processor in MHz), total amount of RAM - ram (in Mb), hard disk drive capacity - hd (in Gb), CD ROM speed - cd (for example, '4x'), and the price. The table "Laptop" is similar to that one of PCs except for the CD ROM speed, which is replaced by the screen size - screen (in inches). For each printer in the table "Printer" it is told whether the printer is color or not (color attribute is 'y' for color printers; otherwise it is 'n'), printer type (laser, jet, or matrix), and the price.

Find the printer makers which also produce PCs with the lowest RAM and the highest-speed processor among PCs with the lowest RAM. Result set: maker.

My query:
select maker from (select maker, model from product where type in ('printer','pc')) as a where model in (select model from (select model, speed, min(ram) as ram from pc where speed=(select max(speed) from pc) group by speed, model) as a)

Result:
Incorrect.
* Wrong number of records (less by 1)
The results of your query:
maker
A

Correct query:
maker
A
E


I really need your help!! I've been trying since yesterday to sort it out...

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 02/03/2012 :  10:54:45  Show Profile  Reply with Quote

SELECT p.maker 
FROM
(
SELECT *,DENSE_RANK() OVER (ORDER BY ram ASC,speed DESC) AS Rnk
FROM Product p
INNER JOIN (SELECT maker
            FROM Product 
            WHERE type IN ('PC','printer')
            GROUP BY maker
            HAVING COUNT(DISTINCT type)=2
           )p1
ON p1.maker = p.maker
INNER JOIN PC  
ON PC.model = p.model
)t
WHERE Rnk=1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gmb.dorr
Starting Member

USA
4 Posts

Posted - 01/22/2013 :  17:32:39  Show Profile  Reply with Quote
I'm stuck in this problem too! Anyone help please?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 01/23/2013 :  00:59:23  Show Profile  Reply with Quote
quote:
Originally posted by gmb.dorr

I'm stuck in this problem too! Anyone help please?


did you try the solution posted?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000