Assignmnet 2
Assignmnet 2
# PART A
# NAME: KRUSHNA MAKHAR
# PRN: 202101070060
#To display details of all Trains which start from New Delhi
SELECT * FROM trains
WHERE START='New Delhi';
#To display PNR, Pname, Gender, Age of all passengers whose age is below 50.
SELECT PNR, PNAME, GENDER, AGE
FROM passengers
WHERE AGE<=50;
#To display records of all passengers travelling to trains whose TNO is 12015
# by using inner joined
SELECT passengers.PNR, passengers.PNAME, passengers.GENDER, passengers.AGE,
trains.TNAME, trains.START, trains.END
FROM passengers
JOIN trains ON passengers.TNO = trains.TNO
WHERE passengers.TNO = 12015;
# by subquery
SELECT PNR, PNAME, GENDER, AGE
FROM passengers
WHERE TNO = (SELECT TNO FROM trains WHERE TNO = 12015);
#Corrected query
SELECT MAX(TRAVELDATE), MIN(TRAVELDATE)
FROM Passengers
WHERE GENDER = 'Female';
###########
##########
########
# PART 2
##########
########
#########
#To display Name and Price of all the accessories in descending order of their Price.
SELECT Name, price
FROM Accessories
ORDER BY Price DESC;
#To display Id and Sname of all the Shoppe location in ‘Nehru Place’.
SELECT ID, SName
FROM Shoppe
WHERE Area='Nehru Place';
#To display Name, Minimum and Maximum Price of each name from Accessories table.
SELECT Name, MIN(Price) AS MinPrice, MAX(Price) AS MaxPrice
FROM Accessories
GROUP BY Name;
#To display Name, Price of all Accessories and their respective SName from Table Shoppe and
Accessories where Price is 5000 or more.
SELECT a.Name, a.Price, s.SName
FROM Accessories a
JOIN Shoppe s ON a.Id = s.Id
WHERE a.Price >= 5000;
# To display all details of accessories where name contains the word ‘Board’;
SELECT *
FROM Accessories
WHERE Name LIKE '%Board%';
SELECT *
FROM Shoppe AS S
JOIN Accessories AS A ON S.Id = A.Id
WHERE A.Price >= 10000;