0% found this document useful (0 votes)
2 views

Sumit SQL Project

The document contains SQL practical questions for Class XII-A students at PM Shri Jawahar Navodaya Vidyalaya, Faridabad, for the academic year 2024-2025. It includes various SQL commands and queries related to student data, employee records, sports performance, and product management, along with expected outputs for each query. The document serves as a guide for students to practice and understand SQL operations in different contexts.

Uploaded by

anshulchhawdi3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Sumit SQL Project

The document contains SQL practical questions for Class XII-A students at PM Shri Jawahar Navodaya Vidyalaya, Faridabad, for the academic year 2024-2025. It includes various SQL commands and queries related to student data, employee records, sports performance, and product management, along with expected outputs for each query. The document serves as a guide for students to practice and understand SQL operations in different contexts.

Uploaded by

anshulchhawdi3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SUMIT XII-A SQL- PRACTICAL QUESTIONS

PM SHRI JAWAHAR NAVODAYA VIDYALAYA


FARIDABAD HARYANA

COMPUTER SCIENCE (083)


SQL- PRACTICAL QUESTIONS

SUBMITTED BY : SUMIT
CLASS AND SECTION:XII-A
ROLL NUMBER :

STRUCTURED QUERY LANGUAGE


PRACTICAL QUESTIONS
2024-2025

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS

Q1: Write SQL commands for the following statements.

S.NO NAME STIPEND SUBJECT AVERAGE DIV.


1 KARAN 400 PHYSICS 68 I
2 DIWAKAR 450 COMP. Sc. 68 I
3 DIVYA 300 CHEMISTRY 62 I
4 REKHA 350 PHYSICS 63 I
5 ARJUN 500 MATHS 70 I
6 SABINA 400 CEHMISTRY 55 II
7 JOHN 250 PHYSICS 64 I
8 ROBERT 450 MATHS 68 I
9 RUBINA 500 COMP. Sc. 62 I
10 VIKAS 400 MATHS 57 II

1. List the names of those students who have obtained DIV I sorted by NAME
Ans: SELECT NAME FROM GRADUATE WHERE DIV=’I’ ORDER BY NAME;
2. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in
a year assuming that the STIPEND is paid every month.
Ans:SELECT NAME,STIPEND,SUBJECT,STIPEND*12 as “AMT PAID” FROM GRADUATE;
3. To count the number of students who are either PHYSICS or COMP.SC. graduates
Ans:SELECT COUNT(*) FROM GRADUATE WHERE SUBJECT IN (‘PHYSICS’,’COMP.SC’);
4. To insert a new row in the GRADUATE table: 11, 'KAJOL', 300,'COMP.SC.', 75,'I'.
Ans:INSERT INTO GRADUATE VALUES( 11, 'KAJOL', 300,'COMP.SC.', 75,’I’);
Give the output of the following SQL queries.

1. SQL> SELECT MIN(AVERAGE)FROM GRADUATE WHERE (SUBJECT='PHYSICS');


Ans:63
SQL> SELECT SUM(STIPEND) FROM GRADUATE WHERE(DIV='II');
Ans:112
2. SQL> SELECT AVG(STIPEND)FROM GRADUATE WHERE(AVERAGE>=65);
Ans:450
3. SQL> SELECT COUNT( DISTINCT SUBJECT )FROM GRADUATE;
Ans:4

Q2: Consider the following table EMPLOYEE and SALGRADE and answer (b) and (c) part of
the Question:

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
Table: EMPLOYEE

ECODE NAME DESIG SGRADE DOJ DOB

101 Abdul Ahmad EXECUTIVE S03 23-Mar-2003 13-Jan-1980

102 Ravi Chandra HEAD-IT S02 12-Feb-2010 22-Jul-1987

103 John Ken RECEPTIONIST S03 24-Jan-2009 24-Feb-1983

104 NazarAmeen GM S02 11-Aug-2006 03-Mar-1984

105 PriyamSen CEO S01 29-Dec-2004 19-Jan-1982


Table:SALGRADE
SGRADE SALARY HRA

S01 56000 18000

S02 32000 12000

S03 24000 8000

(b) Write SQL commands for the following statements:

(i) To display the details of all EMPLOYEES in descending order of DOJ.


ANS:SELECT * FROM EMPLOYEE ORDER BY DOJ DESC;
(ii) To display NAME and DESIG of those EMPLOYEES whose SALGRADE is either S02 or
SO3.
ANS:SELECT NAME,DESIG FROM EMPLOYEE WHERE SGRADE IN(„S02‟,‟S03‟);
(iii) To display the content of all the EMPLOYEES table, whose DOJ is in between 09-Feb-
2006 and 08-Aug-2009.
ANS:SELECT * FROM EMPLOYEE WHERE DOJ BETWEEN ‟09-Feb-2006‟ and ‟08-Aug-
2009‟
(iv) To add a new row with the following
109, „Harish Roy‟, „HEAD-IT‟, „S02‟,‟09-Sep-2007‟, ‟21-Apr-1983‟
ANS:INSERT INTO EMPLOYEE VALUES (109, „Harish Roy‟, „HEAD-IT‟, „S02‟,‟09-Sep-
2007‟, ‟21-Apr-1983);

(c) Give the output of the following SQL queries :

(i) SELECT COUNT(SGRADE), SGRADE FROM EMPLOYEE GROUP BY SGRADE;

ANS:COUNT(SGRADE), SGRADE
1 S01
2 S02
2 S03

(ii) SELECT MIN(DOB), MAX(DOJ) FROM EMPLOYEE;


ANS:MIN(DOB), MAX(DOJ)
13-JAN1980 12-FEB-2010
(iii) SELECT NAME,SALARY FROM EMPLOYEE E, SALGRADE S
WHERE E.SGARDE=S.SGRADE AND E.ECODE<103;

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
ANS:NAME SALARY
Abdul Ahmad 24000
Ravi chandra 32000
(iv) SELECT SGRADE, SALARY+HRA FROM SALGRADE WHERE SGRADE=‟S02‟
Ans:SGRADE SALARY+HRA
S02 44000

Q3: Write SQL command for (i) to (vii) on the basis of the table SPORTS

Table: SPORTS
Student NO Class Name Game1 Grade Game2 Grade2
10 7 Sammer Cricket B Swimming A
11 8 Sujit Tennis A Skating C
12 7 Kamal Swimming B Football B
13 7 Venna Tennis C Tennis A
14 9 Archana Basketball A Cricket A
15 10 Arpit Cricket A Atheletics C

(a) Display the names of the students who have grade „C‟ in either Game1 or Game2
or both
ANS:SELECT NAME FROM SPORTS WHERE GRADE IN („C‟) OR GRADE2 IN („C‟);

(b) Display the number of students getting grade „A‟ in Cricket.


ANS:SELECT COUNT(Student NO) FROM SPORTS WHERE Grade =„A‟ AND
Game1=„Cricket‟ OR Grade2=„A‟ AND Game2=„Cricket‟;
(c) Display the names of the students who have same game for both Game1 and
Game2.
ANS:SELECT NAME FROM SPORTS WHERE Game1=Game2;
(d) Display the games taken up by the students, whose name starts with „A‟.
ANS:SELECT Game1, Game2 FROM SPORTS WHERE Name LIKE „A%‟;
(e) Assign a value 200 for Marks for all those who are getting grade „B‟ or grade „A‟ in
both Game1 and Game2.
ANS:ALTERTABLE SPORTS ADD MARKS NUMBER(3);
UPDATE SPORTS SET MARKS=200 WHERE Grade1 IN („A‟,‟B‟) AND Grade 2 IN
(„A‟,‟B‟);
(f) Arrange the whole table in the alphabetical order of Name.
ANS: SELECT * FROM SPORTS ORDER BY Name;
(g) Add a new column named „Marks‟.
ANS: ALTER TABLE SPORTS ADD MARKS NUMBER(3);

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS

Q4: Write SQL command for (i) to (vii) on the basis of the table Employees
&EmpSalary

Table: Employees

Empid Firstname Lastname Address City

010 Ravi Kumar Raj nagar GZB

105 Harry Waltor Gandhi nagar GZB

152 Sam Tones 33 Elm St. Paris

215 Sarah Ackerman 440 U.S. 110 Upton

244 Manila Sengupta 24 Friends street New Delhi

300 Robert Samuel 9 Fifth Cross Washington

335 Ritu Tondon Shastri Nagar GZB

400 Rachel Lee 121 Harrison St. New York

441 Peter Thompson 11 Red Road Paris

Table:EmpSalary
Empid Salary Benefits Designation

010 75000 15000 Manager

105 65000 15000 Manager

152 80000 25000 Director

215 75000 12500 Manager

244 50000 12000 Clerk

300 45000 10000 Clerk

335 40000 10000 Clerk

400 32000 7500 Salesman

441 28000 7500 salesman

Write the SQL commands for the following:

(i) To show firstname,lastname,address and city of all employees living in


paris
ANS:SELECTFirstname ,Lastname ,Address ,City FROM Employees WHERE
City=„Paris‟;
(ii) To display the content of Employees table in descending order of
Firstname.
ANS:SELECT * FROM Employees ORDER BY „Firstname‟ DESC;

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
(iii) To display the firstname,lastname and total salary of all managers from the
tables Employee and empsalary , where total salary is calculated as
salary+benefits.
ANS:SELECTFirstname,Lastname,TOTALSALARY=Salary+Benefits FROM
Employees E,EmpSalary S WHERE E.Empid=S.Empid;
(iv) To display the maximum salary among managers and clerks from the table
Empsalary
ANS:SELECT MAX(Salary) FROM Empsalary WHEREDesignationIN(„Manager‟
,‟Clerk‟);

Give the Output of following SQL commands:


(i) Select firstname,salary from employees ,empsalarywhere designation =
„Salesman‟ and Employees.empid=Empsalary.empid;
ANS:Firstname salary
Rachel32000
Peter 28000

(ii) Select count(distinct designation) from empsalary;


ANS: count(distinct Designation)
4
(iii) Select designation, sum(salary) from empsalary group by designation
having count(*) >2;
ANS: Designation sum(Salary)
Manager 2,15,000
Clerk 1,35,000
(iv) Select sum(benefits) from empsalary where designation =‟Clerk‟;
ANS: sum(Benefits)
32000
Q5:Write SQL command for (i) to (vii) on the basis of the table Employees
&EmpSalary

Table : SchoolBus

Rtno Area_overed Capacity Noofstudents Distance Transporter Charges

1 Vasantkunj 100 120 10 Shivamtravels 100000

2 HauzKhas 80 80 10 Anand travels 85000

3 Pitampura 60 55 30 Anand travels 60000

4 Rohini 100 90 35 Anand travels 100000

5 Yamuna Vihar 50 60 20 Bhalla Co. 55000

6 Krishna Nagar 70 80 30 Yadav Co. 80000

7 Vasundhara 100 110 20 Yadav Co. 100000

8 PaschimVihar 40 40 20 Speed travels 55000

9 Saket 120 120 10 Speed travels 100000

10 JankPuri 100 100 20 Kisan Tours 95000

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS

(b) To show all information of students where capacity is more than the no of student in
order of rtno.
Ans:SELECT * FROM SchoolBus WHERE Capacity >Noof students ORDER BY Rtno;
(c) To show area_covered for buses covering more than 20 km., but charges less then
80000.
ANS:SELECT SUM (Distance) FROM SchoolBus WHERE Distance>20 AND
Charges<80000;
(d) To show transporter wise total no. of students traveling.
(e) ANS:SELECT Transporter,SUM(Noostudents) FROM SchoolBus GROUP BY
Transporter;
(f) To show rtno, area_covered and average cost per student for all routes where
average cost per student is - charges/noofstudents.
ANS:SELECTRtno,Area_Overed,AVERAGECOST=Charges/Noofstudents FROM
Schoolbus;
(g) Add a new record with following data:
(11, “ Moti bagh”,35,32,10,” kisan tours “, 35000)
ANS:INSERT INTO SchoolbusVALUES(11, “ Moti bagh”,35,32,10,” kisan tours “, 35000) ;
(h) Give the output considering the original relation as given:
(i) select sum(distance) from schoolbus where transporter= “ Yadav travels”;
ANS:50
(ii) select min(noofstudents) from schoolbus;
ANS:40
(iii) selectavg(charges) from schoolbus where transporter= “ Anand travels”;
ANS:81,666.66
(i) select distinct transporter from schoolbus;
ANS:6

Q6:Write SQL queries to perform the following based on the table PRODUCT having fields as
(prod_id, prod_name, quantity, unit_rate, price, city)

i. Display those records from table PRODUCT where prod_id is more than 100.
ANS:SELECT * FROM PRODUCT WHERE prod_id>100;
ii. List records from table PRODUCT where prod_name is „Almirah‟
ANS:SELECT * FROM PRODUCT WHERE prod_name=„ALMIRAH‟;
iii. List all those records whose price is between 200 and 500.
ANS:SELECT * FROM PRODUCT WHERE price BETWEEN 200 AND 500;
iv. Display the product names whose price is less than the average of price.
ANS:SELECTprod_name FROM PRODUCT WHEREprise<AVG(prise);
v. Show the total number of records in the table PRODUCT.
ANS:SELECT COUNT(*) FROM PRODUCT;

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
Q7: Write SQL commands for (i) to (viii) on the basis of relations given below:

BOOKS
book_id Book_name author_name Publishers Price Type qty
k0001 Let us C Sanjay mukharjee EPB 450 Comp 15
p0001 Genuine J. Mukhi FIRST PUBL.755 Fiction 24
m0001 Mastering c++ Kanetkar EPB 165 Comp 60
n0002 Vc++ advance P. Purohit TDH 250 Comp 45
k0002 Near to heart Sanjeev FIRST PUBL. 350 Fiction 30

ISSUED
Book_ID Qty_Issued

L02 13

L04 5

L05 21

i. To show the books of FIRST PUBL Publishers written by P.Purohit.


ANS:SELECTPublishersFROM BOOKS WHERE author_name=P.Purohit;
ii. To display cost of all the books written for FIRST PUBL.
ANS:SELECT SUM(Prise) FROM BOOKS WHERE Publishers =„FIRST PUBLISHERS‟;
iii. Depreciate the price of all books of EPB publishers by 5%.
ANS:SELECTPrise = Prise - Prise * 5% FROM BOOKS WHERE Publishers =“EPB”;
iv. To display the BOOK_NAME,price of the books whose more than 3 copies have been issued.
ANS:SELECTBook_name,Prise,Qty_Issued FROM BOOKS,ISSUED WHERE Qty_Issued>3 AND
BOOKS.book_id=ISSUED.Book_ID;
v. To show total cost of books of each type.
ANS:SELECT SUM(Prise) FROM BOOKS GROUP BY Type;
vi. To show the detail of the most costly book.
ANS:SELECT * FROM BOOKS WHERE Prise=MAX(Prise);

Q8: Write SQL commands for (a) to (f) and write output for (g) on the basis of
PRODUCTS relation given below:

PRODUCT TABLE
PCODE PNAME COMPANY PRICE STOCK MANUFACTURE WARRANTY
P001 TV BPL 10000 200 12-JAN-2008 3
P002 TV SONY 12000 150 23-MAR-2007 4
P003 PC LENOVO 39000 100 09-APR-2008 2
P004 PC COMPAQ 38000 120 20-JUN-2009 2
P005 HANDYCAM SONY 18000 250 23-MAR-2007 3
a) To show details of all PCs with stock more than 110.
ANS:SELECT * FROM PRODUCT TABLE WHERE STOCK>110;
b) To list the company which gives warranty for more than 2 years.
ANS:SELECT COMPANY FROM PRODUCT TABLE WHERE WARRANTY>2;
c) To find stock value of the BPL company where stock value is sum of the products of price
and stock.

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
ANS:SELECT STOCKVALUE=SUM(STOCK*PRICE) FROM PRODUCT TABLE
WHERE COMPANY=„BPL‟;
d) To show number of products from each company.
ANS:SELECT COUNT(*) FROM PRODUCT TABLE GROUP BY PNAME;
e) To count the number of PRODUCTS which shall be out of warranty on 20-NOV-2010.
ANS:SELECT COUNT(*) FROM PRODUCT TABLE WHERE 20-NOV-2010;
f) To show the PRODUCT name which are within warranty as on date.
ANS:SELCET PNAME FROM PRODUCT TABLE WHERE WARRANTY=SYSDATE;
g). Give the output of following statement.
(i) Select COUNT(distinct company) from PRODUCT.
ANS:4
(ii) Select MAX(price)from PRODUCT where WARRANTY<=3
ANS:18000

Q9: Write a SQL commands for (i) to (iv) and write the output for (v) on the basis of
table FURNITURE.

Table: FURNITURE
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT

1 White lotus Double Bed 23/02/02 30000 25

2 Pink feather Baby cot 20/01/02 7000 20

3 Dolphin Baby cot 19/02/02 9500 20

4 Decent Office Table 01/01/02 25000 30

5 Comfort Zone Double Bed 12/01/02 25000 25

6 Donald Baby cot 24/02/02 6500 15

7 Royal Finish Office Table 20/02/02 18000 30

8 Royal tiger Sofa 22/02/02 31000 30

9 Econo sitting Sofa 13/12/01 9500 25

10 Eating Paradise Dining table 19/02/02 11500 25

(i) To list the ITEMNAME which are priced at more than 15000 from the
FURNITURE table?
ANS:SELECT ITEMNAME FROM FURNITURE WHERE PRICE>15000;
(ii) To list ITEMANME and TYPE of those items, in which DATEOFSOTCK is before
22/01/02 from FURNITURE table in descending order of ITEMNAME.
ANS:SELECT ITEMNAME FROM FURNITURE WHERE DATASTOCK<22/01/22 ORDER BY
ITEMNAME DESC;

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
(iii) To display ITEMANME and DATEOFSTOCK of those items, in which the
discount percentage is more than 25 from FURNITURE table.
ANS:SELECT ITEMNAME AND DATEOFSTOCK FROM FURNITURE WHERE
DISCOUNT>25;
(iv) To count the number of items, whose TYPE is “sofa” from FURNITURE table.
ANS:SELECT COUNT(*) FROM FURNITURE WHERE TYPE=“SOFA”;
(v) Give the output of the following SQL statement.
(a)SELECT AVG(DISCOUNT) from FURNITURE where TYPE=’Baby cot’;
ANS:18.3
(b)Select SUM(PRICE) FROM FURNITURE WHERE DATEOFSTOCK<{12/02/02};
ANS:3

Q10:
1. What is relation? What is the difference between a tuple and an attribute?
ANS: A TABLE IS KNOWN AS RELATION.ROWS IS CALLED TUPLE AND COLUMNS
KNOWNS AS ATTRIBUTE.
2. What are DDL and DML?
ANS: DATA DEFINITION LANGUAGE AND DATA MANIPULATION LANGUAGE
3. Differentiate between primary key and candidate key in a relation?
ANS:PRIMARY KEY IS A UNIQUE KEY IN A TABLE AND THE KEYS WHICH ARE
TREATED AS A PRIMARY KEY IN A TABLE IS KNOWN AS CANDIDATE KEY.
4. What do you understand by the terms Cardinality and Degree of a relation in
relational database?
ANS: CARDINALITY IS THE NUMBER OF TUPLES AND DEGREE IS THE NUMBER OF
ATTRIBUTES.
5. Differentiate between DDL and DML. Mention the 2 commands for each caterogy.
ANS: DATA DEFINITION LANGUAGE -CREATE TABLE,ALTER TABLE,DROP TABLE
DATA MANIPULATION LANGUAGE -INSERT INTO,UPDATE SET,DELETE.

Q11: Consider the following tables FACULTY and COURSES. Write SQL
Commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)
FACULTY
F_ID Fname Lname Hire_date Salary

102 Amit Mishra 12-10-1998 12000

103 Nitin Vyas 24-12-1994 8000

104 Rakshit Soni 18-5-2001 14000

105 Rashmi Malhotra 11-9-2004 11000

106 Sulekha Srivastava 5-6-2006 10000

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD


SUMIT XII-A SQL- PRACTICAL QUESTIONS
107 Niranjan Kumar 26-8-1996 16000

COURSES
C_ID F_ID Cname Fees

C21 102 Grid Computing 40000

C22 106 System Design 16000

C23 104 Computer Security 8000

C24 106 Human Biology 15000

C25 102 Computer Network 20000

C26 105 Visual Basic 6000

C27 107 Dreamweaver 4000

(I) To display details of those Faculties whose date of joining is before 31-12-2001.
ANS:SELECT * FROM FACULTY WHERE Hire_date<31-12-2001;
(ii) To display the details of courses whose fees is in the range of 15000 to 50000
(both values included).
ANS:SELECT * FROM COURSES WHERE Fees BETWEEN 15000 AND 50000;
(iii) To increase the fees of Dreamweaver course by 500.
ANS:SELECT Fees=Fees+500 FROM COURSES WHERE Cname=Dreamweaver 4000;
OR:UPDATE COURSES SET Fees=Fees+500 WHERE COURSES=“Dreamweaver 4000”
(iv) insert new column in a COURSES named Level with String type..
ANS:ALTER TABLE COURSES ADD LEVEL VARCHAR2(20)
(v) Select COUNT(DISTINCT F_ID) from COURSES;
ANS:5
(vi) Select MIN(Salary) from FACULTY,COURSES where COURSES.F_ID
=FACULTY.F_ID;
ANS:105 AND 103

SESSION 2024-25 PM SHRI JAWAHAR NAVODAYA VIDYALAYA,FARIDABAD

You might also like