sql project file file 1 and 2
sql project file file 1 and 2
Consider the following tables INVENTORY and DEALERS and answer the questions given below:
Table: INVENTORY
ITEMNO ITEM DCOD QTY UNITPRICE STOCKDATE
Table: DEALERS
DCODE DNAME
101 Reliable Stationaries
103 Class Plastics
104 Fair Deals
102 Clear Deals
i. To display details of all the items in the INVENTORY table in ascending order of stockdate.
To display details of all products from INVENTORY Table whose unitprices more than 8 rs.
Ans. SELECT * FROM INVENTORY WHERE UNITPRICE>8);
iii. To display the details of those items whose dealer code is 103 or QUANTITY IN STORE is less
than 100 from the table INVENTORY.
Ans. SELECT * FROM INVENTORY WHERE DCODE-103 OR OTY<100;
v. To display minimum rate of Items for each dealer individually as per DCODE from the table
INVENTORY.
Ans. SELECT DCODE, MIN (UNITPRICE) FROM INVENTORY, DEALER WHERE DEALER. DCODE-
INVENTORY. DOODE GROUP BY DEALER.DCODE;
2. Consider the following tables ZOO and KEEPERS and answer the questions given below:
Table: ZOO
ENNO ANIMAL KCDE NUMBER DATE OF ADMISSION
Table: KEEPERS
KCODE KNAME
SH222 Sohan Kumar
AP101 Ajay Pal
GP204 Gagan Punaya
RR402 Ritesh Rawat
ii. To display details of all animals who are looked after by Ritesh Rawat.
Ans. SELECT * FROM ZOO, KEEPERS WHERE ZOO.KCODE-KEEPERS.KCODE AND KNAME='Ritesh
Rawat';
iii. To display the total number of animals taken care of by each keeper.
Ans. SELECT KCODE, SUM(NUMBER) FROM ZOO GROUP BY KCODE;
iv. To display the name of the keeper who looks after Tree monkeys
Ans. SELECT KNAME FROM ZOO, KEEPER WHERE ZOO.KCODE KEEPER.KCODE AND ANIMAL='Tree
Monkey';
Table: TOYSHOP
SNO NAME SCODE QUANTITY PRICE TYPE
Table: SUPPLIERS
SCODE SNAME
H222 Rohan Kumar
P101 Vijay Pal
G204 Garv Punaya
R402 Ritwij Rawat
iv. To display the name of the supplier who supplies Tennis Raquets.
Ans. SELECT SNAME FROM TOYSHOP, SUPPLIERS WHERE TOYSHOP.SCODE-SUPPLIERS.SCODE AND
NAME='Tennis Raquets';
v. To add a new column, DateofOrder of the type date to the table toyshop.
Ans. ALTER TABLE TOYSHOP ADD DATEOFORDER DATE;
4. Consider the following tables SCHOOL and ADMIN and write SQL queries for the given
questions:
Table: SCHOOL
CODE TEACHER NAME SUBJECT DOJ PERIODS EXPERIENCE
Table: ADMIN
CODE DESIGNATION GENDER
1001 HOD Male
1009 Coordinator Female
1203 Vice Principal Female
1167 Coordinator Male
i. To display TEACHERNAME, PERIODS of all teachers whose PERIODS are more than 25.
Ans. SELECT TEACHERNAME, PERIODS FROM SCHOOL WHERE PERIODS>25;
iii . To display designation without duplicate entries from the table ADMIN.
Ans. SELECT DISTINCT DESIGNATION FROM ADMIN;
v. To display TEACHERNAME, CODE and corresponding designation from tables SCHOOL and
ADMIN of male teachers.
Ans. SELECT TEACHERNAME, SCHOOL.CODE, DESIGNATION FROM SCHOOL, ADMIN WHERE SCHOOL.
CODE-ADMIN.CODE AND GENDER-'Male';
5.Consider the following tables COLLEGE and FACULTY and write SQL queries for the given
questions:
Table: COLLEGE
COURSEID NAME NO_ENROLLMENTS DURATION
S003 M.B.A. 60 1
Table: FACULTY
FCODE NAME DESIGNATION COURSEID DEPARTMENT
i. To display Course name and duration for all the courses having more than 150 enrollments.
Ans. SELECT NAME, DURATION FROM COLLEGE WHERE NO_OF_ENROLLMENTS>150;
ii. To display designation without duplicate entries from the table FACULTY.
Ans. SELECT DISTINCT DESIGNATION FROM FACULTY;
Table: TEACHER
T_ID NAME AGE DEPARTMENT DATE_OF_JOIN SALARY GENDER
1 Jugal 34 Computer Sc 10/01/2017 12000 M
2 Sharmila 31 History 24/03/2008 20000 F
3 Sandeep 32 Mathematics 12/12/2016 30000 M
4 Sangeeta 35 History 01/07/2015 40000 F
5 Rakesh 42 Mathematics 05/09/2007 25000 M
6 Shyam 50 History 27/06/2008 30000 M
7 Shiv Om 44 Computer Sc 25/02/2017 21000 M
8 Shalakha 33 Mathematics 31/07/2018 20000 F
Table: POSTING
P_ID DEPARTMENT PLACE
1 History Agra
2 Mathematics Raipur
3 Computer Science Delhi
DEPARTMENT COUNT(*)
History 3
Computer Sc 2
Mathematics 3
iii. SELECT TEACHER. NAME, TEACHER. DEPARTMENT, POSTING.PLACE FROM TEACHR, POSTING
WHERE
TEACHER. DEPARTMENT POSTING. DEPARTMENT AND POSTING.PLACE="Delhi";
Ans.
Table: TEACHER
T_ID NAME AGE DEPARTMENT DATE_OF_JOIN SALARY GENDER
Table: POSTING
P_ID DEPARTMENT PLACE
1 History Agra
2 Mathematics Raipur
ii. To list the names of female teachers who are in Mathematics department.
Ans. SELECT NAME FROM TEACHER WHERE DEPARTMENT= "Mathematics" AND GENDER= "F";
iii. To list the names of all teachers with their date of joining in ascending order.
Ans. SELECT NAME FROM TEACHER ORDER BY DATE_OF_JOIN;
iv. To display teacher's name, salary, age for male teachers only.
Ans. SELECT NAME, SALARY, AGE FROM TEACHER WHERE GENDER='M';
V. To display name, bonus for each teacher where bonus is 10% of salary.
Ans. SELECT NAME, SALARY*0.1 AS BONUS FROM TEACHER;
3.Write SQL queries for (a) to (d) based on the tables PASSENGER and FLIGHT given below:
Table: Passenger
Table: Flight
i. Write a query to change the fare to 6000 of the flight whose FNO is F104.
Ans. UPDATE Flight SET FARE-6000 WHERE FNO='F104';
ii. Write a query to display the total number of MALE and FEMALE PASSENGERS.
Ans. SELECT GENDER, COUNT(*) FROM Passenger GROUP BY GENDER;
iii. Write a query to display the NAME, corresponding FARE and F_DATE of all PASSENGERS who
have a flight to START from DELHI.
Ans. SELECT NAME, FARE, F DATE FROM Passenger p, Flight f WHERE P.FNO=F.FNO AND
START='DELHI';
iv. Write a query to delete the records of flights which end at Mumbai.
Ans. DELETE FROM Flight WHERE END='MUMBAI';
4.Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT given below:
Table: EMPLOYEE
Table: DEPARTMENT
a. Display the MatchID of all those matches where both the teams have scored more than 70.
b. Display the MatchID of all those matches where FirstTeam has scored less than 70 but Second
Team has scored more than 70.
c. Display the MatchID and date of matches played by Team 1 and won by it.
d. Display the MatchID of matches played by Team 2 and not won by it.
e. Change the name of the relation TEAM to T DATA. Also change the attributes TeamID and
TeamName to T_ID and T NAME respectively.
Ans. A. Select MatchIdD from MATCH_DETAILS where FirstTeamScore < 70 and SecondTeamScore >
70:
b. Select MatchIdD from from MATCH_DETAILS where FirstTeamScore < 70 and SecondTeamScore >
70:
c Select MatchIdD, MatchDate from MATCH_ FirstTeamScore DETAILS where FirstTeamID - 1 and
FirstTeamScore > SecondTeamScore;
d. Select MatchIdD, MatchDate from MATCH DETAILS where FirstTeamID = 2 and FirstTeamScore <
SecondTeamScore;
Select MatchIdD, MatchDate from MATCH_DETAILS where Second TeamID - 2 and FirstTeamScore >
SecondTeamScore;