Title:- I’m Here -Taxi Reservation
Declaration:
We hold a copy of this assignment that we can produce if the original is lost or damaged.
We hereby certify that no part of this assignment has been copied from any other group’s work
or from any other source. No part of this assignment has been written / produced for our group
by another person except where such collaboration has been authorized by the subject
lecturer/tutor concerned.
Group Members:
Student ID Student Name Signature
BM14047398 D.M Wijayasinghe
BM14413070 D.K.S.M Munasinghe
BM 14404160. S.N.M.N.S Kosgolla
BM 12416172 P.P.L.N.D Jayaratne
BM14418648 T.Nivedha
Note: An examiner or lecturer/tutor has the right not to mark this assignment if the above
declaration has not been signed
Database Management Systems
Assignment
The ER diagram
Passenger
P_ID
Fname
Lname
Address
Phone
Make Reservation
ResID
Date
Select
Package
PKID
Name Dis_Rate
e
Vehicle
V_Type
V_number
Seat_c
Air_c
Type
Have Driver
D_ID
F_name
L_name
Age
NIC
dl_no
Phone
Take
Trip
Trid
P_location
D_Location
Distance
1
Wating_time
1
1
1 1
N
1
1
Provided
by
Company
Proid Name
1
1
Trip_fare
N
Address
Phone
WTC
Make
1
Call
C_id
Date
N
Description
Ratting
V_id
Promo_code
Duration
Give
1
1
1
1
1
1
1
N
The Relational schema
Passenger (P_ID, Fname, Lname, Address, Phone)
Reservation (Res_id, V_type,Date_promo_code,PID, PkID)
Package (PKID, Name, Dis_rate, Wtc)
Vehicle (V_id ,V_number, Type, color, model, Air_c, Seat_c, D_id, Pro_id)
Company (Pro_id, Name, Address, phone)
Driver (D_id, Age, DL_NO, Fname, Lname, NIC, Phone, NIC, Rating)
Call (C_ID , Date, Duration, Destination, D_id)
Trip (Trid , P_location, D_location, Distance, waiting_time, Tirp_fare, Res_id, V_id)
Create table & insert records - SQL queries
create table passenger
(
P_id int,
fname varchar(25),
lname varchar(25),
address varchar(50),
phone int
constraint pk_p primary key (p_id) )
create table package
(
pkid int,
name varchar(6),
WTC real,
dis_rate real ,
constraint pk_P1 primary key (pkid)
)
create table company
(
proid int,
name varchar(50),
address varchar(25),
phone char(12)
constraint pk_c primary key (proid)
)
create table vehicle
(
vid int,
d_id int,
vnumber char(8),
proid int,
type varchar(6),
Colour Varchar(20),
Model varchar (50),
Air_c varchar(10),
seat_c int,
constraint pk_v primary key (vid),
constraint fk_v foreign key (proid) references company,
constraint fk_d foreign key (d_id) references driver,
constraint ty_pe check (type in('TUK','MINI','CAR')),
constraint air check (Air_C in('A/C','Non A/C'))
)
create table driver
(
d_id int,
fname char(20),
lname char(20),
Nic char(10),
age char(2),
dl_no char(10),
phone char(12),
rating int
constraint pk_d primary key (d_id),
constraint D_g check(age<50),
constraint rate check(rating<10)
)
create table calls
(
c_id int,
D_id int,
date date,
duration time,
description char(50),
constraint cid primary key (C_id),
constraint Did foreign key (d_id) references driver
)
create table reservation
(
resid int,
pkid int,
pid int,
v_type varchar(6),
date datetime,
promo_code char(10),
constraint pk_r primary key (resid),
constraint FK_p foreign key (pid) references passenger(P_id),
constraint FK_r foreign key (pkid) references package (pkid)
)
create table trip
(
trid int,
resid int,
vid int,
P_location char(25),
D_location char(25),
distance int,
waiting_time int,
trip_fare money,
constraint pk_id primary key (trid),
constraint rs_id foreign key (resid) references reservation (resid),
constraint v_id foreign key (vid) references vehicle (vid)
)
insert into package
values (1,'gold',0.5,0.20)
insert into vehicle
values ('2','4','AAR6595','1','TUK' ,'Blue','Bajaj','Non A/C','3')
insert into driver
values ('4' ,'Somawardane', 'Siyasinghe', '741921650V', '42', 'B1529770',
'716308207' ,'8'
)
insert into passenger
values (
2,'Sunimal','Rodrigo','329/7,jubili lane,walana,panadura','778751217'
)
insert into company
values ('1','Link Lanka','Galle rd colombo','011 7 533544')
insert into reservation
values (1,1,1,'Car','2016-04-16','Airtel')
insert into trip
values
(
1,1,15,'Kollupitiya Junction','Kaduwela bus Stand','16','5','650'
)
1. Retrieve the Passengers detailswhose first name starting with letter A to N.
select *
from passenger
where fname like '[A-n]%'
2. Retrieve details of the drivers who’s rating more than 5 and age less than 35
select *
from driver
where rating>5 and age<35
3. Retrieve the details of all Tuk type vehicles
select *
from vehicle
where type='TUK'
4. Retrieve the number of vehicles for each type of vehicles
select Type,count(type) as 'number of vehicles'
from vehicle
group by type
5. Retrieve the names of the drivers who have mini type vehicles and their model
select d.fname,d.lname,v.model
from vehicle v,driver d
where d.d_id=v.d_id and v.type='mini'
6. Retrieve the pick location, Drop location and waiting time cost for all trips
select t.P_location,d_location,p.wtc*t.waiting_time as 'waiting time cost'
from reservation r,package p,trip t
where p.pkid=r.pkid and t.resid= r.resid
order by [waiting time cost]
7. Retrieve the all the driver;s names who have trip fare more than driver id 4’s trip
fare
select d.fname,d.lname,v.vid,v.type,sum(t.trip_fare) as 'Total Trip Fare'
from vehicle v,trip t,driver d
where t.vid=v.vid and v.d_id=d.d_id
group by d.fname,d.lname,v.vid,v.type
having sum(t.trip_fare)>
(
select sum(t.trip_fare) as 'Total Trip Fare'
from vehicle v,trip t,driver d
where t.vid=v.vid and v.d_id=d.d_id and d.d_id=4
)
8. Retrieve the total income by each vehicle and got more than 3000
select v.vid,sum(t.trip_fare) as 'Total income'
from trip t,vehicle v
where t.vid=v.vid
group by v.vid
having sum(t.trip_fare)>3000
order by [Total income]
9. Retrieve the names of the drivers with corresponding with their vehicle number
and vehicle type
select d.fname,d.lname,v.vnumber,v.type
from vehicle v,driver d
where v.d_id=d.d_id
10. Retrieve the pick_location , drop_location, waiting cost for all trips by waiting
time cost descending order
select t.P_location,d_location,p.wtc*t.waiting_time as 'waiting time cost'
from reservation r,package p,trip t
where p.pkid=r.pkid and t.resid= r.resid
order by [waiting time cost] desc
11. Retrieve the driver id, name and rating whose rating equal to driver id 4
select d_id ,fname,lname
from driver
where rating =
(
select rating
from driver
where d_id=4
) and d_id<>4
12. Retrieve the vehicle id and average waiting time where greater than average
waiting time of vehicle id=2
select vid,avg(waiting_time )'Average waiting time'
from trip
group by vid
having avg(waiting_time)<
(
select avg(waiting_time)
from trip
where vid=2
)
13. Retrieve the information such as driver full name, vehicle id and type where total
trip fare greater than 1500 and order by according to trip fare
select d.fname,d.lname,v.vid,v.type,sum(t.trip_fare) 'Total Trip Fare'
from vehicle v,trip t,driver d
where t.vid=v.vid and v.d_id=d.d_id
group by d.fname,d.lname,v.vid,v.type
having sum(t.trip_fare)>1500
order by sum(t.trip_fare) desc
14.

DBMS VIVA Report

  • 1.
    Title:- I’m Here-Taxi Reservation Declaration: We hold a copy of this assignment that we can produce if the original is lost or damaged. We hereby certify that no part of this assignment has been copied from any other group’s work or from any other source. No part of this assignment has been written / produced for our group by another person except where such collaboration has been authorized by the subject lecturer/tutor concerned. Group Members: Student ID Student Name Signature BM14047398 D.M Wijayasinghe BM14413070 D.K.S.M Munasinghe BM 14404160. S.N.M.N.S Kosgolla BM 12416172 P.P.L.N.D Jayaratne BM14418648 T.Nivedha Note: An examiner or lecturer/tutor has the right not to mark this assignment if the above declaration has not been signed Database Management Systems Assignment
  • 2.
    The ER diagram Passenger P_ID Fname Lname Address Phone MakeReservation ResID Date Select Package PKID Name Dis_Rate e Vehicle V_Type V_number Seat_c Air_c Type Have Driver D_ID F_name L_name Age NIC dl_no Phone Take Trip Trid P_location D_Location Distance 1 Wating_time 1 1 1 1 N 1 1 Provided by Company Proid Name 1 1 Trip_fare N Address Phone WTC Make 1 Call C_id Date N Description Ratting V_id Promo_code Duration Give 1 1 1 1 1 1 1 N
  • 3.
    The Relational schema Passenger(P_ID, Fname, Lname, Address, Phone) Reservation (Res_id, V_type,Date_promo_code,PID, PkID) Package (PKID, Name, Dis_rate, Wtc) Vehicle (V_id ,V_number, Type, color, model, Air_c, Seat_c, D_id, Pro_id) Company (Pro_id, Name, Address, phone) Driver (D_id, Age, DL_NO, Fname, Lname, NIC, Phone, NIC, Rating) Call (C_ID , Date, Duration, Destination, D_id) Trip (Trid , P_location, D_location, Distance, waiting_time, Tirp_fare, Res_id, V_id)
  • 4.
    Create table &insert records - SQL queries create table passenger ( P_id int, fname varchar(25), lname varchar(25), address varchar(50), phone int constraint pk_p primary key (p_id) ) create table package ( pkid int, name varchar(6), WTC real, dis_rate real , constraint pk_P1 primary key (pkid) ) create table company ( proid int, name varchar(50), address varchar(25), phone char(12) constraint pk_c primary key (proid) ) create table vehicle ( vid int, d_id int, vnumber char(8), proid int, type varchar(6), Colour Varchar(20), Model varchar (50), Air_c varchar(10), seat_c int, constraint pk_v primary key (vid), constraint fk_v foreign key (proid) references company, constraint fk_d foreign key (d_id) references driver, constraint ty_pe check (type in('TUK','MINI','CAR')), constraint air check (Air_C in('A/C','Non A/C')) )
  • 5.
    create table driver ( d_idint, fname char(20), lname char(20), Nic char(10), age char(2), dl_no char(10), phone char(12), rating int constraint pk_d primary key (d_id), constraint D_g check(age<50), constraint rate check(rating<10) ) create table calls ( c_id int, D_id int, date date, duration time, description char(50), constraint cid primary key (C_id), constraint Did foreign key (d_id) references driver ) create table reservation ( resid int, pkid int, pid int, v_type varchar(6), date datetime, promo_code char(10), constraint pk_r primary key (resid), constraint FK_p foreign key (pid) references passenger(P_id), constraint FK_r foreign key (pkid) references package (pkid) )
  • 6.
    create table trip ( tridint, resid int, vid int, P_location char(25), D_location char(25), distance int, waiting_time int, trip_fare money, constraint pk_id primary key (trid), constraint rs_id foreign key (resid) references reservation (resid), constraint v_id foreign key (vid) references vehicle (vid) ) insert into package values (1,'gold',0.5,0.20) insert into vehicle values ('2','4','AAR6595','1','TUK' ,'Blue','Bajaj','Non A/C','3') insert into driver values ('4' ,'Somawardane', 'Siyasinghe', '741921650V', '42', 'B1529770', '716308207' ,'8' ) insert into passenger values ( 2,'Sunimal','Rodrigo','329/7,jubili lane,walana,panadura','778751217' ) insert into company values ('1','Link Lanka','Galle rd colombo','011 7 533544') insert into reservation values (1,1,1,'Car','2016-04-16','Airtel') insert into trip values ( 1,1,15,'Kollupitiya Junction','Kaduwela bus Stand','16','5','650' )
  • 7.
    1. Retrieve thePassengers detailswhose first name starting with letter A to N. select * from passenger where fname like '[A-n]%' 2. Retrieve details of the drivers who’s rating more than 5 and age less than 35 select * from driver where rating>5 and age<35 3. Retrieve the details of all Tuk type vehicles select * from vehicle where type='TUK'
  • 8.
    4. Retrieve thenumber of vehicles for each type of vehicles select Type,count(type) as 'number of vehicles' from vehicle group by type 5. Retrieve the names of the drivers who have mini type vehicles and their model select d.fname,d.lname,v.model from vehicle v,driver d where d.d_id=v.d_id and v.type='mini' 6. Retrieve the pick location, Drop location and waiting time cost for all trips select t.P_location,d_location,p.wtc*t.waiting_time as 'waiting time cost' from reservation r,package p,trip t where p.pkid=r.pkid and t.resid= r.resid order by [waiting time cost]
  • 9.
    7. Retrieve theall the driver;s names who have trip fare more than driver id 4’s trip fare select d.fname,d.lname,v.vid,v.type,sum(t.trip_fare) as 'Total Trip Fare' from vehicle v,trip t,driver d where t.vid=v.vid and v.d_id=d.d_id group by d.fname,d.lname,v.vid,v.type having sum(t.trip_fare)> ( select sum(t.trip_fare) as 'Total Trip Fare' from vehicle v,trip t,driver d where t.vid=v.vid and v.d_id=d.d_id and d.d_id=4 ) 8. Retrieve the total income by each vehicle and got more than 3000 select v.vid,sum(t.trip_fare) as 'Total income' from trip t,vehicle v where t.vid=v.vid group by v.vid having sum(t.trip_fare)>3000 order by [Total income] 9. Retrieve the names of the drivers with corresponding with their vehicle number and vehicle type select d.fname,d.lname,v.vnumber,v.type from vehicle v,driver d where v.d_id=d.d_id
  • 10.
    10. Retrieve thepick_location , drop_location, waiting cost for all trips by waiting time cost descending order select t.P_location,d_location,p.wtc*t.waiting_time as 'waiting time cost' from reservation r,package p,trip t where p.pkid=r.pkid and t.resid= r.resid order by [waiting time cost] desc 11. Retrieve the driver id, name and rating whose rating equal to driver id 4 select d_id ,fname,lname from driver where rating = ( select rating from driver where d_id=4 ) and d_id<>4
  • 11.
    12. Retrieve thevehicle id and average waiting time where greater than average waiting time of vehicle id=2 select vid,avg(waiting_time )'Average waiting time' from trip group by vid having avg(waiting_time)< ( select avg(waiting_time) from trip where vid=2 ) 13. Retrieve the information such as driver full name, vehicle id and type where total trip fare greater than 1500 and order by according to trip fare select d.fname,d.lname,v.vid,v.type,sum(t.trip_fare) 'Total Trip Fare' from vehicle v,trip t,driver d where t.vid=v.vid and v.d_id=d.d_id group by d.fname,d.lname,v.vid,v.type having sum(t.trip_fare)>1500 order by sum(t.trip_fare) desc
  • 12.