The Database Scheme Consists of Four Tables
The Database Scheme Consists of Four Tables
Q1)
Find the model number, speed and hard drive capacity for all the PCs with prices below $500.
Result set: model, speed, hd.
--Solution:
--Solution:
Q3) Find the model number, RAM and screen size of the laptops with prices over $1000.
--Solution:
Select model, ram, screen from laptop where price > 1000
Q4) Find all records from the Printer table containing data about color printers.
--Solution:
Q5) Find the model number, speed and hard drive capacity of PCs cheaper than $600 having a 12x
or a 24x CD drive.
--Solution:
Select model, speed, hd from pc where price < 600 and cd in ('12x', '24x')
SQL EXCERSISE
Q6) For each maker producing laptops with a hard drive capacity of 10 Gb or higher, find the
speed of such laptops. Result set: maker, speed.
--Solution:
select distinct p.maker, l.speed from product p inner join laptop l on p.model = l.model where l.hd >=
10
Q7) Get the models and prices for all commercially available products (of any type) produced by
maker B.
--Solution:
select product.model, laptop.price from product inner join laptop on product.model = laptop.model
where product.maker = 'B'
union
union
select product.model, pc.price from product inner join pc on product.model = pc.model where
product.maker = 'B'
--Solution:
select distinct maker from product where type = 'PC' and maker not in (select maker from product
where type = 'laptop')
Q9) select distinct maker from product where type = 'PC' and maker not in (select maker from
product where type = 'laptop')
--Solution:
select distinct maker from product inner join pc on product.model = pc.model and pc.speed >= 450
Q10) Find the printer models having the highest price. Result set: model, price.
--Solution:
select distinct model, price from printer where price = (select max(price) from printer)
--Solution:
--Solution:
Q13) Find out the average speed of the PCs produced by maker A.
--Solution:
Select avg(speed) from pc inner join product on pc.model = product.model where product.maker
= 'A'
Q14) For the ships in the Ships table that have at least 10 guns, get the class, name, and country.
--Solution:
from product
where maker in ( select maker from (select maker, type from product group by maker, type) x
group by x.maker
having count(type) = 1
Q15) Get hard drive capacities that are identical for two or more PCs.
Result set: hd.
--Solution:
Select hd from pc
group by hd
--Solution:
from pc p1
inner join pc p2
on p1.speed = p2.speed
Q17) Get the laptop models that have a speed smaller than the speed of any PC.
Result set: type, model, speed.
--Solution:
Select distinct 'Laptop' as Type, model, speed from laptop where speed < (select min(speed) from
pc)
--Solution:
from product
on product.model = printer.model
Q19) For each maker having models in the Laptop table, find out the average screen size of the
laptops he produces.
Result set: maker, average screen size.
--Solution:
FROM LAPTOP
group by product.maker
Q20) Find the makers producing at least three distinct models of PCs.
Result set: maker, number of PC models.
SQL EXCERSISE
--Solution:
Q21) Find out the maximum PC price for each maker having models in the PC table. Result set:
maker, maximum price.
--Solution:
inner join pc
on product.model = pc.model
group by product.maker
Q22) For each value of PC speed that exceeds 600 MHz, find out the average price of PCs with
identical speeds.
Result set: speed, average price.
--Solution:
group by speed