You are on page 1of 2

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.

1. Find the model number, speed and hard drive capacity for all the PCs with prices below $500. Result set: model, speed, hd.
Ans: select model,speed,hd from PC where price<500 2. Find printer makers.Result set: maker. Ans:select distinct maker from product where type='printer' 3. Find the model number, RAM and screen size of the laptops with prices over $1000. Ans: select model,ram,screen from laptop where price>1000 4. Find all the records from the Printer relation for color printers. Ans: select * from printer where color='Y' 5. Find the model number, speed and hard drive capacity of the PCs having 12x CD and prices less than $600 or having 24x CD and prices less than $600. Ans: select model,speed,hd from pc where (cd='12x' and price <600) or (cd='24x' and price<600) 6. Find the makers of the PCs that have speed not less than 450MHz. Result set: Maker. Ans: select distinct product.maker from product,pc where product.model=pc.model and product.type='pc' and pc.speed>=450 7. Point out the maker and speed of the laptops having hard drive capacity more or equal to 10 Gb. select distinct product.maker,laptop.speed from product,laptop where product.model=laptop.model and hd>=10 8. Find the models of printers having the highest price. Result set: model, price. Ans : select model,price from printer where price=(select max(price) from printer)

9. Find out the average speed of PCs. Ans: select avg(speed) from pc 10. Find out the average speed of the laptops priced over $1000. Ans: select avg(speed) from laptop where price>1000 11. Find out the average speed of the PCs produced by maker A. Ans: select avg(pc.speed)from pc,product where product.model=pc.model and product.maker='A'

12. For each value of speed find the average price of the PC with the same processor speed. Result set: speed, average price.
Ans: select speed,avg(price) from pc group by speed 13. For each maker find out the average screen size of the laptops produced by it. Result set: maker, average screen size. Ans: select Product.maker, avg(Laptop.screen) as Average from Product,Laptop where product.model=Laptop.model group by Product.maker

14. Define the maximal price of PC produced by each maker. Result set: maker, maximal price. Ans: select distinct product.maker,max(pc.price) from product,pc where product.model=pc.model group by product.maker