0% found this document useful (0 votes)
23 views10 pages

sql project file file 1 and 2

Project Class 12 computer

Uploaded by

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

sql project file file 1 and 2

Project Class 12 computer

Uploaded by

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

1.

Consider the following tables INVENTORY and DEALERS and answer the questions given below:

Table: INVENTORY
ITEMNO ITEM DCOD QTY UNITPRICE STOCKDATE

5005 Bell Pen 0.5 102 100 16 2011-03-31


5003 Ball Pen 0.25 102 150 20 2010-01-01

5002 Gel Pen Premium 101 125 14 2010-02-14


5006 Gel Pen Classic 101 200 22 2009-01-09

5001 Eraser S mall 102 210 5 2009-03-19


5004 Eraser Big 102 60 10 2010-12-12

5009 Sharpener Classic 103 160 8 2010-01-23

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.

Ans. SELECT * FROM INVENTORY ORDER BY 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;

iv. To increase the price of all the items by 2%.


Ans. UPDATE INVENTORY SET UNITPRICE-UNITPRICE+0.02 * UNITPRICE;

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

5005 Black Bear SH222 2 2012-03-18

5003 Leopard AP101 1 2011-01-02

5002 Panda GP204 4 2014-02-15

5006 Tree Monkey SH222 7 2015-01-11

5001 Lin RR402 1 2009-03-22

5004 Antelope AP101 4 2015-12-15

5009 Rhinq RR402 2 2012-01-24

Table: KEEPERS

KCODE KNAME
SH222 Sohan Kumar
AP101 Ajay Pal
GP204 Gagan Punaya
RR402 Ritesh Rawat

i. To display details of all the animals in descending order of Date Of admission.


Ans. SELECT * FROM 200 ORDER BY DATEOFADMISSION DESC:

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';

v. To increase the number of lions by by 7.


Ans. UPDATE ZOO SET NUMBER-NUMBER+7 WHERE ANIMAL="Lion";
3.Consider the following tables TOYSHOP and SUPPLIERS and write SQL queries for the given
questions:

Table: TOYSHOP
SNO NAME SCODE QUANTITY PRICE TYPE

T005 Ball H222 20 450 HF

T003 Ludo P101 60 200 GF

T004 Stuffed Panda G204 40 650 TF

T006 Monopoly S222 70 780 GF

T001 Tennis Raquet R402 40 1150 GF

T007 Train Tracks A101 85 990 HF

T002 Singing Doll R402 25 470 GF

Table: SUPPLIERS
SCODE SNAME
H222 Rohan Kumar
P101 Vijay Pal
G204 Garv Punaya
R402 Ritwij Rawat

To display the highest price of each type of toy.


Ans. SELECT TYPE, MAX(PRICE) FROM TOYSHOP GROUP BY TYPE;

ii. To display the toys which are supplied by Ritwij Rawat..


Ans. SELECT NAME FROM TOYSHOP, SUPPLIERS WHERE TOYSHOP.SCODE-SUPPLIERS.SCODE AND
SNAME-'Ritwij Rawat';

iii. To display the total quantity of toys supplied by each supplier.


Ans. SELECT SCODE, SUM(QUANTITY) FROM TOYSHOP GROUP BY SCODE;

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

1001 Ravi Shankar English 12/03/2000 24 10

1009 Priya Rai Physics 03/09/1998 26 12

1203 Lisa Anand English 09/04/2000 27 5

1045 Yashraj Maths 24/08/2000 24 15

1123 Ganan Physics 16/07/1999 28 3

1167 Harish B Chemistry 19/10/1999 27 5

1215 Umesh Physics 11/05/1998 22 16

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;

ii. To display the information of the most senior teacher.


Ans. SELECT TEACHERNAME FROM SCHOOL HAVING MAX (EXPERIENCE);

iii . To display designation without duplicate entries from the table ADMIN.
Ans. SELECT DISTINCT DESIGNATION FROM ADMIN;

iv. To display the average experience of teachers of each SUBJECT.


Ans. SELECT SUBJECT, ANG (EXPERIENCE) FROM SCHOOL GROUP BY SUBJECT:

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

S001 B.Tech CSE 150 4

S002 B.B.A. 200 4

S003 M.B.A. 60 1

S004 B.Ed 250 2

S005 M.C.A. 110 3

S006 B.C.A. 350 2

Table: FACULTY
FCODE NAME DESIGNATION COURSEID DEPARTMENT

F202 Rinku Sharma Lecturer S006 CS


F204 Priyanka Chaturvedi Professor S006 IT

F205 Fiona John Professor S002 Bst


F206 Trionka Verma Senior Lecturer S001 CSE

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 the information of teacherswhose designation is Professor.


Ans. SELECT * FROM FACULTY WHERE DESIGNATION='Professor';

ii. To display designation without duplicate entries from the table FACULTY.
Ans. SELECT DISTINCT DESIGNATION FROM FACULTY;

iv. To display the total number of enrollments in the college.


Ans. SELECT SUM (NO_OF_ENROLLMENTS) FROM COLLEGE;

v. To display department and designation of the faculty members teaching "B.C.A.".


Ans. SELECT DEPARTMENT, DESIGNATION FROM FACULTY, COLLEGE WHERE
FACULTY.COURSEID=COLLEGE. COURSEID;
1.Write the outputs of the SQL queries (i) to (iii) based on the relations TEACHER and POSTING
given below:

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

i. SELECT DEPARTMENT, COUNT(*) FROM TEACHER GROUP BY DEPARTMENT;


Ans.

DEPARTMENT COUNT(*)
History 3
Computer Sc 2
Mathematics 3

ii. SELECT MAX(DATE OF JOIN), MIN(DATE OF JOIN) FROM TEACHER:


Ans. Max-31/07/2018 or 2018-07-31
Min-05/09/2007 or 2007-09-05

iii. SELECT TEACHER. NAME, TEACHER. DEPARTMENT, POSTING.PLACE FROM TEACHR, POSTING
WHERE
TEACHER. DEPARTMENT POSTING. DEPARTMENT AND POSTING.PLACE="Delhi";
Ans.

NAME DEPARTMENT PLACE


Jugal Computer Sc Delhi
Shiv Om Computer Sc Delhi
2.Write SQL commands for the following queries (i) to (v) based on the relations TEACHER and
POSTING given below:

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

i. To show all information about the teacher of History department.


Ans. SELECT * FROM TEACHER WHERE DEPARTMENT= "History";

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

PNO NAME GENDER FNO


1001 Suresh Male F101
1002 Anita Female F104
1003 Harjas Male F102
1004 Nita Female F103

Table: Flight

FNO START END F_DATE FARE


F101 MUMBAI CHENNAI 2021-12-25 4500
F102 MUMBAI BENGALURU 2021-11-20 4000

F103 DELHI CHENNAI 2021-12-10 5500


F104 KOLKATA MUMBAI 2021-12-20 4500
F105 DELHI BENGALURU 2021-01-15 5000

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

EMPID NAME DOB DEPTID DESIG SALARY


120 Alisha 23-Jan-1978 D001 Manager 75000
123 Nitin 10-Oct-1977 D002 AO 59000
129 Navjot 12-Jul-1971 D003 Supervisor 40000
130 Jimmy 30-Dec-1980 D004 Sales Rep
131 Faiz 06-Ap-1984 D001 Dep Manager 65000

Table: DEPARTMENT

DEPTID DEPTNAME FLOORNO


D001 Personal 4
D002 Admin 10
D003 Production 1
D004 Sales 3

a. To display the average salary of all employees, department wise.


b. To display name and respective department name of each employee whose salary is
more than 50000.
c. To display the names of employees whose salary is not known, in alphabetical order.
d. To display DEPTID from the table EMPLOYEE without repetition.

Ans. a. SELECT AVG(SALARY) FROM EMPLOYEE GROUP BY DEPTID;


b. SELECT NAME, DEPTNAME FROM EMPLOYEE, DEPARTMENT WHERE EMPLOYEE.DEPTID=
DEPARTMENT DEPTID AND SALARY>50000;
C. SELECT NAME FROM EMPLOYEE WHERE SALARY IS NULL ORDER BY NAME;
d. SELECT DISTINCT DEPTID FROM EMPLOYEE;
5.Using the sports database containing two relations (TEAM, MATCH DETAILS) and write the
queries for the following:

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;

e. ALTER TABLE Team RENAME TO T_DATA;

ALTER TABLE T_DATA CHANGE COLUMN TeamID T ID int;

ALTER TABLE T DATA CHANGE COLUMN TeamName T Name;

You might also like