100% found this document useful (1 vote)
278 views

Database Management System

This document contains a lab experiment on performing various SQL queries using nested queries, joins, and complex queries. The queries include finding train names by destination, fare details, passenger names by boarding station, trains with all AC coaches and base fare less than 3000, and more. Complex queries involve finding number of substations per train, stations where all train types stop, trains with at least four bookings, and creating tables for cancellation history and total seats by train and class. No data was found for some of the example queries given.

Uploaded by

Jaanaavi Wasade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
278 views

Database Management System

This document contains a lab experiment on performing various SQL queries using nested queries, joins, and complex queries. The queries include finding train names by destination, fare details, passenger names by boarding station, trains with all AC coaches and base fare less than 3000, and more. Complex queries involve finding number of substations per train, stations where all train types stop, trains with at least four bookings, and creating tables for cancellation history and total seats by train and class. No data was found for some of the example queries given.

Uploaded by

Jaanaavi Wasade
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Database Management System

Lab Experiments
Name: Jaanaavi Wasade

Registration Number:18BCE0743

USE NESTED QUERY


1. Find the train names that stop in 'Katpadi'.

SQL> select * from train where destination = 'KATPADI';

no data found.

2. Find the train names that are superfast and the service tax is zero.

SQL> SELECT * FROM TRAIN_TICKET_FARE WHERE SUPERFAST_CHARGE>0 AND

SERVICE_TAX=0;

no data found.

3.Find the Passenger name who have booked for the train that starts from 'Chennai'.

SQL> SELECT P_NAME FROM PASSENGER WHERE PNR_NO IN (SELECT PNRNO FROM
TICKET WHERE
TRAIN_NUMBER IN ( SELECT TRAIN_NUMBER FROM TRAIN WHERE SOURCE =
'CHENNAI' ));
no data found.

4. Find the trains names that have all the AC coaches and the base fare is less than 3000 for each case.

SQL> SELECT TRAIN FROM TRAIN WHERE TRAIN_NO IN (SELECT TRAIN_NO FROM
TRAIN_TICKET_FARE WHERE CLASS='1A' OR CLASS = '2A' OR CLASS = '3A' AND
BASEFARE < 3000)

Use Join Query

1. Find the train names that stop in 'Katpadi'.

SQL> SELECT Train.train_number, Train.name FROM Train JOIN Ticket ON train_number =


train_number WHERE Train.destination= ‘KATPADI’;

no data found.

2. Find the train names that are superfast and the service tax is zero.

SQL> SELECT Train.train_number, Train.name FROM Train JOIN Train_Ticket_fare ON


train_number = train_number WHERE Train_Ticket_fare .superfast_charge >0 and
Train_Ticket_fare.service_tax=0;

no data found.

3. Find the Passenger name (and train name) who have booked for the train that starts from 'Chennai'.
SQL> SELECT Train.train_number, Train.name, Passenger.Name FROM Passenger INNER JOIN
Train, Ticket ON Passenger.PNRNo=Ticket.PNRNo WHERE Ticket.from_station=’CHENNAI’;

no data found.

Complex querries
1. List the train names and the number of substations it has.

SQL> SELECT Ticket.tostation, count(Train.type) AS count type FROM Train,Ticket WHERE

(SELECT count(Train.type)FROM Train)=count type

GROUP BY (tostation);

2. List the stations where all types of trains stop.

SQL>SELECT station FROM Trainroute WHERE Trainnumber=ALL

SELECT trainnumber FROM Train);

3. List the trains names that has atleast four bookings.

SQL>SELECT Train.name FROM Train WHERE Train.number in (SELECT Train.number FROM


Train intersect SELECT Train.number FROM Ticket GROUP BY Train.number having count(*>>2)

4. Create a table cancellation history(insert values from ticket and passenger table)

SQL>SELECT name, count(PNRno) countbooking FROM train inner join Ticket on


Train.trainnumber=ticketnumber WHERE count booking>4 GROUP BY(Train.name);

5. Create a table for all the train numbers and class available in train_ticket_fare with total seats.
SQL>CREATE TABLE SETS AS SELECT trainnumber,class FROM TIC_FARE

SQL> SELECT * FROM SETS ORDER BY trainnumber;

6.Find the station name that has highest number of train stopping at.

SQL>SELECT tostation,max(trainnumber) FROM Train, Ticket WHERE


Train.trainnumber=Ticket.trainnumber

GROUP BY (tostation);

You might also like