Return to Assignments
Answers to Assignment 2 based on Car Rental Database
Write SELECT statements for each of the following:
Selectc.cust_no,c.cust_name,
c.address,b.date_rent_start
from customers c, bookings b
where c.cust_no=b.cust_no;
select cust.cust_no, car.model_name, car.registration, cg.rate_per_day, cg.rate_per_mile, b.date_reserved
from customers cust,cars car, cargroups cg, bookings b
where cust.cust_no = b.cust_no
and b.registration=car.registration
and car.car_group_name=cg.car_group_name
and car.car_group_name='A1'
select b.registration, car.Car_group_name, car.model_name, cg.rate_per_day, b.date_rent_start, b.cust_no, cust.cust_name, cust.address
from bookings b, cargroups cg, customers cust, cars car
where cust.cust_no = b.cust_no
and b.registration=car.registration
and car.car_group_name=cg.car_group_name
and b.date_reserved>#2/1/92#;
select car.model_name, car.registration, cg.rate_per_day
from cars car, cargroups cg
where car.car_group_name = cg.car_group_name and cg.rate_per_day <
(select distinct cg2.rate_per_day
from cargroups cg2, cars car2
where cg2.car_group_name=car2.car_group_name
and car2.model_name = 'P944 T')
select cust_no, cust_name, Town from customers where cust_no in
(select cust_no from bookings
where reserved_by='jane b')
select car.model_name, b.registration, b.date_rent_start, b.cust_no, cust.town
from cars car, bookings b, customers cust
where car.registration=b.registration
and b.cust_no=cust.cust_no
and cust.cust_no in
(select cust_no from customers
where town='London'
or town = 'Bristol'
or town = 'Birmingham')
select car.model_name, car.registration, car.car_group_name, cg.rate_per_day
from cars car, cargroups cg
where car.car_group_name=cg.car_group_name
and cg.rate_per_day =
(select min(rate_per_day) from cargroups)
select count(*)
from cargroups
where car_group_name in
(select distinct car_group_name from cars)
select count(*)
from bookings
where date_rent_start>=#1/1/89#
and date_rent_start<=#12/31/89#
group by pay_method
having pay_method = 'C';
select model_name, car_group_name, maint_int
from models
order by car_group_name asc, maint_int desc;
create view MyView as
select b.cust_no, c.car_group_name, c.model_name, b.date_reserved, b.reserved_by, b.date_rent_start, b.rental_period, b.pay_method
from bookings b, cars c
where b.registraion=c.registration;
select registration, tochar(date_bought, "The DDth day of Month, yyyy")
from cars
where car_group_name='A2';
MSAccess Version:
select registration,Format("The " & Format(Now, "dd") & "th day of " & Format(Now, "mmm") & " Month, " & Format(Now, "yyyy"), "")
from cars
where car_group_name='A2';
Return to Assignments