Computer Science Project of SQL
Computer Science Project of SQL
SCHOOL
COMPUTER
SCIENCE
(2021-2022)
SUBMITTED TO
MS. RUCHIKA ANAND
SUBMITTED BY
KAMAL SINGH
SUKHEEJA
XIITH – S1
21
1) Write a Python program to implement a Stack using list (PUSH ,POP, PEEK,& Display the Element of
Stack).
2) Write a python program using function PUSH(Arr), where Arr is a list of numbers. From this list push all
numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one
element, otherwise display appropriate error message.
3) Write a python program using function POP(Arr), where Arr is a stack implemented by a list of
numbers. The function returns the value deleted from the stack.
4) Write a function in python, MakePush(Package) and MakePop(Package) to add a new Package and
delete a Package from a List of Package Description, considering them to act as push and pop operations of
the Stack data structure.
5) Write a function LShift(Arr,n) in Python, which accepts a list Arr of numbers and n is a numeric
value by which all elements of the list are shifted to left.
Sample Input Data of the list Arr= [ 10,20,30,40,12,11], n=2 OutputArr = [30,40,12,11,10,20]
6) Create a table STUDENT with given constraints and insert data
into it. Implement all SQL commands on the table .
CREATE TABLE STUDENT(ROLLNO INTEGER NOT NULL PRIMARY KEY ,
NAME CHAR(20) UNIQUE,
ADDRESS VARCHAR(100) ,
MARKS INT ,
GRADE CHAR(1) DEFAULT 'E',
CHECK (MARKS<=100) );
as follows:
8) Consider the following two table : PRODUCT and CLIENT , Write SQL queries for (i) to (xiii)
and find outputs for SQL queries (xiv) to (xvii), which are based on the tables :
TABLE : PRODUCT
(iii) To display the details of Products from PRODUCT table who’s Price is in the range of
50 to 100.
SELECT * FROM PRODUCT WHERE PRICE BETWEEN 50 AND 100;
(iv) To display the details of those Products from PRODUCT table whose name ends with
'Wash'
SELECT * FROM PRODUCT WHERE PRODUCTNAME LIKE
'%WASH';
(vi) To display details of those Product from PRODUCT table whose ExpiryDate in 2011
SELECT * FROM PRODUCT WHERE YEAR(EXPIRYDATE) =
'2011';
(vii) To display the ProductName, Manufacturer, ExpiryDate of all the products that
expired on or before ‘2010-12-31’.
SELECT PRODUCTNAME,MANUFACTURER,EXPIRYDATE FROM
(viii)To display the ClientName and City of all Mumbai- and Delhi-based clients in Client
SELECT NAME,CITY FROM CLIENT
WHERE CITY IN('MUMBAI','DELHI');
(ix) To display Maximum Price, Minimum Price and total number for each Manufacturer
individually as per Manufacturer from PRODUCT table.
SELECT MAX(PRICE) AS MAX,MIN(PRICE) AS MIN,
(xii) To add new row with the following content in CLIENT table.
2, Cosmetic Shop , Mumbai, FW05
INSERT INTO CLIENT VALUES(2,'COSMETIC SHOP','MUMBAI',
'FW05');
ProductName Price*4
Talcum Powder 160
Face Wash 180
Bath Soap 220
Shampoo 480
Face Wash 380
(xv) Select count(distinct Manufacturer) from Product;
count(distinct Manufacturer)
3
(xvi)Select C_ID, Client_Name, City from Client where City like ‘M%’;
TABLE : DEPT
DOJ refers to Date of Joining and DOB refers to Date of Birth of workers.
(i) To display WNO, NAME,GENDER from the table WORKER in descending order of
WNO.
(ii) To display the NAME of all the FEMALE workers from the table WORKER.
SELECT NAME, GENDER FROM WORKER WHERE
GENDER='Female';
(iii) To display the WNO and NAME of those workers from the table WORKER, who are
born between ‘1987- 01-01’ and ‘1991-12-01’.
SELECT WNO,NAME FROM WORKER
WHERE DOB BETWEEN '1987-01-01' AND '1991-12-01';
(v) To display DeptID and total number of worker who have Salary more than 50000
department wise
SELECT DEPTID,COUNT(*) FROM WORKER
WHERE SALARY>55000 GROUP BY DEPTID ;
(x) To display the WHO , Name, Salary, Deptid, Department, City from table WORKER
and DEPT with their corresponding DeptID
SELECT WNO,NAME,SALARY,WORKER.DEPTID,DEPARTMENT,CITY
FROM WORKER,DEPT WHERE WORKER.DEPTID=DEPT.DEPTID;
(xii) To delete those worker from Worker table whose DEPTID is “D04”
DELETE FROM WORKER WHERE DEPTID='D04';
DISTINCT(DEPARTMENT)
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
(xiv) SELECT NAME, DEPARTMENT, CITY FROM WORKER W, DEPT D
WHERE W.DC0DE=D.DCODE AND WNO<1003;
MAX(DOJ) MIN(DOB)
2013-09-02 1991-09-01
10) Write a output for SQL queries (i) to (v), which are based on the table: STUDENT :
Table: STUDENT
i) To display the records from table student in alphabetical order as per the name of
the student.
ii) To display Class, Dob and City whose marks is between 450 and 551.
SELECT CLASS , DOB , CITY FROM STUDENT WHERE MARKS BETWEEN 450
AND 551;
iv) To display Name, Class and total number of students who have secured more than
450 marks, class wise
SELECT NAME,CLASS ,COUNT(*) FROM STUDENT
Where marks>450 GROUP BY CLASS;
11) In the following table EMP and DEPT perform different Join operation:
TABLE: EMP
• CARTESIAN PRODUCT
SELECT*FROM EMP,DEPT;
• EQUI-JOIN
SELECT*FROM EMP , DEPT WHERE EMP.DEPTNO= DEPT.DEPTNO;
• NATURALJOIN
SELECT DEPTNO FROM EMP NATURAL JOIN DEP ;
12) Integrate MySQL with Python by importing the MySQL module and Create a table Student.
13) Integrate MySQL with Python by importing the MySQL module and add records of student and
display all the record.
INSERT THE DATA
14) Integrate MySQL with Python by importing the MySQL module to search student using RNO and
if present in table display the record, if not display appropriate method.
DIPLAY PARTICULAR DATA
15) Integrate SQL with Python by importing the MySQL module to search a student using RNO and if
present in table delete the record, if not display appropriate method.
16) Integrate SQL with Python by importing the MySQL module to search a student using RNO and if
present in table update the record, if not display appropriate method.
UPDATE THE DATA