Sumit SQL Project
Sumit SQL Project
SUBMITTED BY : SUMIT
CLASS AND SECTION:XII-A
ROLL NUMBER :
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.
Q2: Consider the following table EMPLOYEE and SALGRADE and answer (b) and (c) part of
the Question:
ANS:COUNT(SGRADE), SGRADE
1 S01
2 S02
2 S03
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‟);
Q4: Write SQL command for (i) to (vii) on the basis of the table Employees
&EmpSalary
Table: Employees
Table:EmpSalary
Empid Salary Benefits Designation
Table : SchoolBus
(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;
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
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.
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
(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;
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
COURSES
C_ID F_ID Cname Fees
(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