0% found this document useful (0 votes)
6 views13 pages

info mysql

The document outlines SQL commands for creating and manipulating various database tables including Club, Flights, Employee, Hospital, School, Admin, Bookings, and Package. It includes commands for displaying data, updating records, deleting entries, and aggregating information across different tables. Each section provides specific queries along with their intended outputs.

Uploaded by

j2492618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views13 pages

info mysql

The document outlines SQL commands for creating and manipulating various database tables including Club, Flights, Employee, Hospital, School, Admin, Bookings, and Package. It includes commands for displaying data, updating records, deleting entries, and aggregating information across different tables. Each section provides specific queries along with their intended outputs.

Uploaded by

j2492618
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Table Club:

create table Club(GCode int(4), GName char(11), Number int(1), Fees int(7),
StartingDate date);
i. To display the name of all games with their GCode
Ans: select GCode,GName from Club;
Output:

ii. To display details of those games which have fees more than 7000
Ans: select * from Club where Fees>7000;
Output:

iii. To display content of the club table in descending order of the start date
Ans: select * from club order by StartingDate desc:
Output:

iv. Delete the records of all Game names


Ans: alter table Club drop GName;
Output:

v. List the minimum and maximum fees from the club table
Ans: select min(Fees),max(Fees) from club;
Output:

Table Flight:

create table Fligts(FNO varchar(9) primary key,Source char(15),Dest


char(25),No_of_flights int(2),No_of_stations int(2),Dep_Time int(3),Dep date);

Table Fares:

create table Fares(FNO varchar(9), Airlines char(20), Fares int(5),foreign


key(FNO) references Flights(FNO));

i. Display flight number and number of flights from mumbai from the table
flights
Ans: select FNO,No_of_flights from Flights where Source='Mumbai';
Output:
ii. Arrange the context of the table flights in descending order of destination
Ans: select * from Flights order by Dest desc;
Output:

iii. Increase tax by 2% for the flight starting from Delhi


Ans: update Flights,Fares set Tax_perc=Tax_perc*2/100 where
Source='Delhi' and Flights.FNO=Fares.FNO;
Output:

iv. Display the flight number and fare to be paid for the flight from mumbai
to kochi using the table flights and fares where the fare to be
paid=fare+fare*tax/100
Ans: select Flights.FNO,Fares+Fares*Tax_perc/100 as 'Fares to be paid'
from Flights,Fares where Source='Mumbai' and Dest='Kochi' and
Fares.FNO=Flights.Fno;
Output:

v. Display the total number of source(eliminate duplicate) present in the


table
Ans: select count(distinct Source) from Flights;
output:

vi. Display the fare for the flight from Mumbai to banglore
Ans: select Fares from Fares,Flights where Source='Mumbai' and
Dest='Banglore' and Fares.FNO=Flights.FNO;
Output:

vii. Display the record of source stations started with letter’B’


Ans: select Source from Flights where Source like 'B%';
Output:

viii. Display the flight number for which fare to be paid less than 3000
Ans: select FNO from Fares where Fares<3000;
Output:

ix. Display the total number of flights available for each airline
Ans: select count(No_of_flights),Airlines from Flights,Fares where
Flights.FNO=Fares.FNO group by Airlines;
Output:

x. Delete the record of flight number IC301 from the table fare
Ans: delete from Fares where FNO='IC301';
Output:
xi. Increase the size of the column ‘Source’ to 30 in the table flight
Ans:alter table Flights modify Source varchar(30);
Output:

Table Employee:

create table Employee(Eid int(10) primary key,Name char(30),Depid


int(3),Qualification char(6),Sex char(3));

Table Salary:

create table Salary(Eid int(10),Basis int(10),DA int(10),HRA


int(10),Bonus int(10),foreign key(Eid) references Employee(Eid));

i. Display the frequency of employee departure wise


Ans: select count(*),Depid from Employee group by Depid;
Output:

ii. To list the name of those employees only whose names start with ‘H’
Ans: select Name from Employee where Name like 'H%';
Output:

iii. To add new column in salary table, column name is Total_salary


Ans: alter table Salary add Total_salary int(7);
Output:

iv. To store the corresponding value in the Total_salary column


Ans: update Salary set Total_salary=Basis+DA+HRA+Bonus;
Output:

Table: Hospital

Create table Hospital(Pid int(2), Name varchar(20), Age int(3), Department


varchar(25), Charges int(4),Gender char (1));

i. To display total numbers of employees present in the hospital.


Ans: Select Count(*) from Hospital;
Output:

ii. To display all the information about the patients of cardiology


department.
Ans: Select * from Hospital where Department='Cardiology';
Output:

iii. To list the names of all female patients who are in the ENT department.
Ans: Select Name from Hospital where Department ='ENT' and Gender='F';
Output:

iv. To display name and gender of all the patients whose age is in the range
40 to 50 in ascending order of their name.
Ans: Select Name,Gender from Hospital where Age between 40 and 50 order
by Name;
Output:
Table: School

Create table School(Code int(6),TeacherName varchar(20),Subject


varchar(25),DOJ Date,Periods int(3),Experience int(2));

Table: Admin

Create table Admin(Code int(6),Gender varchar(15),Designation


varchar(25));

i. To display TeacherName, Periods of all the teachers whose periods less


that 25.
Ans: Select TeacherName, Periods from School where Periods < 25;
Output:

ii. To display TeacherName, Code and Designation from Table School and
Admin whose Gender is male.
Ans: Select School.code,Teachername,Designation from School Admin
where gender="Male" and School.Code=Admin.Code;
Output:

iii. To display the number of teacher in each subject.


Ans: Select Count(*) TeacherName,Subject from School group by Subject;
Output:
iv. To display Code, Teacher name and subject of all teachers who have
joined the school after 01/01/1999.
Ans: Select Code, TeacherName, Subject from School where DOJ>1999-01-
01;
Output:
Table: Bookings

Create table Bookings(PCode char(3) primary key,TouristName


varchar(25),Agency varchar(20),No_Of_Persons int(2),Tdate Date);

Table: Package

Create table Package(PCode char(2),PName varchar(20),Per_Person_Amt


int(7), foreign key(PCode) references Booking(PCode));

i. Display the name of all the tourists, their travel dates, name of the place
they are travelling to and the total amount to be paid by each tourist.
Ans: Select TouristName, sum(Per_Person_Amt * No_Of_Persons) as
Total_Amount from Bookings, Package where Bookings.PCode =
Package.PCode Group By TouristName;
Output:
ii. Display the name of all the agencies from the bookings table.
Ans: Select distinct (Agency) from Bookings;
Output:

iii. Arrange the content of the table bookings in ascending order of travel
date.
Ans: Select* from Bookings Order By Tdate;
Output:
iv. Display the maximum number of persons travelling from each travel
agency.
Ans: Select Max(No_Of_Persons),Agency from Bookings Group By
Agency;

Output:

You might also like