XII CS - Term2 - Practicals (2021-22) - Sol
XII CS - Term2 - Practicals (2021-22) - Sol
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.
6
Create a table STUDENT with given constraints and insert data into it. Implement all SQL
commands on the table
A SCHOOL has database MySchool is to be maintain their data details using SQL. As a
database administer, Abhay has decided that :
• Name of the database –MySchool
• Name of the table –STUDENT
• The attributes of STUDENTwith constraints are given as follows:
• Alter the table and change the datatype size for the ENAME from 20 to 35
ALTER TABLE EMPLOYEE MODIFY ENAME VARCHAR(35);
NOTE
C_ID is the Primary Key.
P_ID is the Foreign Key referencing P_ID of Client table.
(i) To display the details of those Clients whose city is Delhi.
SELECT * FROM CLIENT WHERE CITY='DELHI';
(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 PRODUCT
WHERE EXPIRYDATE <='2010-12-31';
(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,
SUM(PRICE) AS SUM FROM PRODUCT GROUP BY MANUFACTURER;
(x) To display the P_ID, ProductName, Manufacturer , Price , C_ID ,Name from table
PRODUCT, CLIENT with their corresponding P_ID
SELECT PRODUCT.P_ID,PRODUCTNAME,MANUFACTURER,PRICE,
C_ID,NAME FROM PRODUCT,CLIENT
WHERE PRODUCT.P_ID=CLIENT.P_ID;
(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');
(xvi)Select C_ID, Client_Name, City from Client where City like ‘M%’;
C_ID NAME City P_ID
6 Total Health Mumbai BS01
9
Write SQL queries for (i) to (xv) and find outputs for SQL queries (xvi) to (xix), which are
based on the tables :
TABLE : DEPT
DeptID DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D04 FINANCE KOLKATA
D05 HUMAN RESOURCE MUMBAI
TABLE : WORKER
WNO Name DOJ DOB Gender Salary DeptID
1001 George K 2013-09-02 1991-09-01 Male 54000 D01
1002 RymaSen 2012-12-11 1990-12-15 Female 60000 D03
1003 Mohitesh 2013-02-03 1987-09-04 Male 55000 D05
1007 Anil Jha 2014-01-17 1984-10-19 Male 66000 D04
1004 Manila Sahai 2012-12-09 1986-11-14 Female 70000 D01
1005 R SAHAY 2013-11-18 1987-03-31 Male 80000 D03
1006 Jaya Priya 2014-06-09 1985-06-23 Female 75000 D05
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.
SELECT WNO,NAME GENDER FROM WORKER ORDER BY 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';
i) To display the records from table student in alphabetical order as per the name of the
student.
SELECT * FROM STUDENT ORDER BY NAME;
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
EMPNO ENAME JOB SAL DEPTNO
8369 SMITH CLERK 2985 10
8499 ANYA SALESMAN 9870 20
8566 AMIR SALESMAN 8760 30
8698 BINA MANAGER 5643 20
TABLE:DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEWDELHI
20 RESEARCH CHENNAI
30 SALES KOLKATA
40 OPERATIONS MUMBAI
• 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.
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.
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.