Вы находитесь на странице: 1из 17

Final assignment of CSE311L

Name :- Mahin Mostafa


ID :- 1721471642
Course :- CSE311
Course Name :- Database Management System
Section :- 07
Faculty :- KMN1
Answer to the question No :1

CREATE TABLE RIDER ( rdr_id INT(20) NULL ,


rname VARCHAR(20) NULL ,
vehicle VARCHAR(20) NULL ,
vtype VARCHAR(20) NULL ,

join_date DATE NULL ,


total_rides INT(20) NULL ,
income DECIMAL(10,2) NULL ,
distance DECIMAL(10,2) NULL , PRIMARY KEY (rdr_id))

INSERT INTO rider VALUES


(1,'Abrar Fahim','Honda Civic', 'C',STR_TO_DATE ('20,03,2020','%d,%m,%Y'), 75, 87000, 1200),
(2,'Jafar Ahmed','Yamaha R15', 'B',STR_TO_DATE ('12,01,2020','%d,%m,%Y'), 55, 60000, 900),
(3,'Jannatul Lamia','Toyota Prius', 'C',STR_TO_DATE ('04,04,2020','%d,%m,%Y'), 30, 33000, 350),

(4,'Tanvir Ahmed','Yamaha Pulsar', 'B',STR_TO_DATE ('01,12,2019','%d,%m,%Y'), 105, 100000,


1370),
(5,'Shahriar Alam','Bajaj Discover', 'B',STR_TO_DATE ('25,01,2020','%d,%m,%Y'), 5 ,1000, 80),
(6,'Ashfaq Nabid','UM Sport', 'B',STR_TO_DATE ('28,09,2020','%d,%m,%Y'), 1 ,350, 22),
(7,'SM Sayem Toyota','Corolla', 'C',STR_TO_DATE ('08,08,2020','%d,%m,%Y'), 15, 5200, 190),
(8,'Golam Haider','Vespa', 'B',STR_TO_DATE ('16,03,2020','%d,%m,%Y'), 45, 52000, 650)

CREATE TABLE PASSENGERS (

pid INT(20) NULL ,


pname VARCHAR(20) NULL ,
join_date DATE NULL , PRIMARY KEY (pid))
INSERT INTO passengers VALUES
(1, 'Shahriar Chowdhury',STR_TO_DATE ('02,01,2020','%d,%m,%Y')),

(2, 'Jamal E Mollah',STR_TO_DATE ('21,10,2019','%d,%m,%Y')),


(3, 'Alvi Hossain',STR_TO_DATE ('12,11,2019','%d,%m,%Y')),
(4, 'Tonmoy Jaman',STR_TO_DATE ('27,01,2020','%d,%m,%Y')),
(5, 'Toukir Munshi',STR_TO_DATE ('02,12,2019','%d,%m,%Y')),

(6, 'Yakub Noby',STR_TO_DATE ('24,12,2019','%d,%m,%Y')),


(7, 'Mithila Rahman',STR_TO_DATE ('27,02,2020','%d,%m,%Y')),
(8, 'Jobbar Sheikh',STR_TO_DATE ('14,03,2020','%d,%m,%Y')),
(9, 'Chunnu Wahidul',STR_TO_DATE ('07,06,2020','%d,%m,%Y')),

(10, 'Rakib Hasan',STR_TO_DATE ('29,08,2020','%d,%m,%Y'))

CREATE TABLE RIDES_TODAY ( rd_id INT(20) NULL ,


rdr_id INT(20) NULL ,
pid INT(20) NULL ,

distance DECIMAL(10,2) NULL ,


bill DECIMAL(10,2) NULL,
PRIMARY KEY (rd_id))

INSERT INTO rides_today VALUES

(1,1 ,7 ,14.3, 480),


(2 ,2 ,10, 1.3, 40),
(3 ,4 ,2 ,8.9 ,110),
(4 ,5 ,4 ,15.5, 260),

(5 ,7 ,3 ,5.1 ,250),
(6 ,1 ,7 ,14.3, 510),
(7 ,1 ,1 ,9.5 ,330),
(8 ,7 ,6 ,5.5 ,280),

(9 ,8 ,10, 8.2, 140),


(10, 4, 8, 5.7, 90),
(11, 2, 2, 3.4, 90),
(12, 8, 6, 12.5, 165),

(13, 4, 8, 15.6, 250),


(14, 3, 6, 8.5, 290),
(15, 4, 2, 5.1, 70)

Answer to the question No :2

-----> SELECT * FROM passengers


---> SELECT * FROM rider

----> SELECT * FROM rides_today


Answer to the Question No : 3
Query :-

SELECT pid,pname FROM passengers


EXCEPT
(SELECT a.pid,a.pname
FROM passengers AS a JOIN rides_today AS b
ON a.pid = b.pid)

Explanation :- Here first table show all passengers name and id then second table show who
ride today and we use “EXCEPT” returns only rows, which are not available in the second Select
statementAnd then print that passenger's id and name which are absent in the second table
and print those name and id.

Answer to The Question No: - 4


Answer :-
SELECT r.rname, r.vehicle,r.vtype,r.income ,p.pname, p.join_date
FROM passengers AS p LEFT JOIN rides_today AS a
ON p.pid = a.pid
LEFT JOIN rider AS r

ON a.rdr_id = r.rdr_id

UNION
SELECT r.rname,r.vehicle,r.vtype,r.income ,p.pname, p.join_date

FROM passengers AS p RIGHT JOIN rides_today AS a


ON p.pid = a.pid
RIGHT JOIN rider AS r
ON a.rdr_id = r.rdr_id
Explanation: Here 1st table print all rider and passengers details with that passenger who do
not take a ride today. Then 2nd table also print rider and passenger details but this table also
print that rider who doesn’t ride today and “UNION” select statement within the UNION must
have the same number of fields in the result sets with similar data types combine 2 tables and
print value.

Answer to the Question No: 5


Answer:-
SELECT SUM(a.bill) AS 'Today Revenue From Car'
FROM rides_today AS a JOIN rider AS r
ON a.rdr_id = r.rdr_id

WHERE r.vtype = 'C'


Explanation: Here we join rider and rider_today table find out the car from different type
vehicle which is used for ride today and also “SUM” all car bill and print that .

Answer to the Question No: 6

Answer :-
SELECT r.rname ,r.vehicle, MAX(rt.distance)
FROM rider AS r JOIN rides_today AS rt
ON r.rdr_id = rt.rdr_id
WHERE r.vtype = 'C'
Explanation: Here we join rider and rider_today table find out car from different type vehicle
which is used for ride today. And we also find out who rides maximum distance through using
“MAX” and show the result.

Answer to the Question No: - 7


Query :-

SELECT r.rname ,r.vehicle, rt.distance


FROM rider AS r JOIN rides_today AS rt
ON r.rdr_id = rt.rdr_id
WHERE r.vtype = 'C' AND rt.distance<10
Explanation: Here we join rider and rider_today table find out car from different type vehicle which is
used for ride today. And also we find out which rider cover distance through less than 10 and show the
result .

Answer to the question No : 8

Query :-

SELECT p.pname,SUM(r.bill) AS 'PAY BILL'


FROM rides_today AS r JOIN passengers AS p
ON r.pid = p.pid
GROUP BY p.pname
Explanation: Here we join passengers and rider_today table and calculate passenger’s
individually pay bill who take ride today and show the result.

Answer to the Question No: 9


Query :-
ALTER TABLE passengers
ADD plevel int(20)
Answer to the Question No:- 10
Query :-
SELECT join_date,

CASE WHEN join_date < '2020-01-01' THEN 3


WHEN join_date < '2020-07-01' THEN 2
ELSE 1 END AS plevel
FROM passengers
Explanation: Here we update the PASSENGERS table’s level column by using WHEN & THEN
operation and we update 01-01-2020 to level 3, 01-07-2020 to level 2 and other who join after
those date to level 1 and show that.

Answer to the question NO :- 12


Query:-
SELECT r.rname,r.vehicle, p.pname, rt.distance,rt.bill
FROM passengers AS p JOIN rides_today AS rt
ON p.pid = rt.pid
JOIN rider AS r
ON rt.rdr_id = r.rdr_id
WHERE r.vtype = 'C'

GROUP BY r.rdr_id
HAVING (COUNT(r.rdr_id)) =1
Explanation: - we use have join to join 2 table and where for search vehicle type and having for count
particular person who complete full single ride and we show the result.

Answer to the question No:- 13

Query :-
SELECT r.rname,r.vehicle,r.vtype,rt.distance,rt.bill

FROM rider AS r JOIN rides_today AS rt

ON r.rdr_id = rt.rdr_id

where r.vtype = 'B '

group by r.rname
Explanation :- Here we 1st table print all rider and rider today who travel with bike . We use
join , where and group by operation to connect 2 table information and show the result .

Answer to the Question No :- 14

Query :-

SELECT r.rname,r.vehicle,r.vtype, p.pname, rt.distance,rt.bill

FROM passengers AS p JOIN rides_today AS rt

ON p.pid = rt.pid

JOIN rider AS r

ON rt.rdr_id = r.rdr_id
Explanation :- Here we 1st table print all rider and passengers details with that passenger who
do take a ride today. Then 2nd table also print rider and passenger details but this table also
print that rider today and all other information by using JOIN operation and show the result .

Вам также может понравиться