Professional Documents
Culture Documents
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
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) );
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:
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';
(ii) To display the details of all PRODUCT in decreasing order of ExpiryDate.
SELECT * FROM PRODUCT ORDER BY EXPIRYDATE DESC;
(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';
(v) To display the distinct City from Client Table.
SELECT DISTINCT CITY FROM CLIENT;
(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;
(xi) To increase the Price of all Product in Product table by 15%
UPDATE PRODUCT SET PRICE=PRICE+0.15*PRICE;
(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%’;
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';
(iv) Show the minimum, maximum and average salary of WORKER.
SELECT MIN(SALARY),MAX(SALARY),AVG(SALARY) FROM WORKER;
(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 ;
(vi) To displayDeptID and maximum salary of worker in each department.
SELECT DEPTID,MAX(SALARY) FROM WORKER GROUP BY DEPTID ;
(vii) Count the Number of Worker working in the Department “D03”
SELECT COUNT(*) FROM WORKER WHERE DEPTID='D03';
(viii) Count number of Male in the WORKER table.
SELECT COUNT(*) FROM WORKER WHERE GENDER ='Male';
(ix) Count distinct city of DEPT table
SELECT COUNT(DISTINCT CITY) FROM DEPT;
(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;
(xi) To increase Salary of all Worker by 2000 whose DeptID is “D05”
UPDATE WORKER SET SALARY=SALARY+2000 WHERE DEPTID='D05';
(xii) To delete those worker from Worker table whose DEPTID is “D04”
DELETE FROM WORKER WHERE DEPTID='D04';
(xiii) SELECT DISTINCT DEPARTMENT FROM DEPT;
DISTINCT(DEPARTMENT)
MEDIA
MARKETING
INFRASTRUCTURE
FINANCE
HUMAN RESOURCE
10 Write a output for SQL queries (i) to (v), which are based on the table: STUDENT :
Table : STUDENT
RNO Name CLASS DOB Gender CITY MARKS
1 Nanda X 06-06-1995 M Agra 551
2 Saurabh XII 07-05-1993 M Mumbai 462
3 Sonal XI 06-05-1994 F Delhi 400
4 Trisla XII 08-08-1995 F Mumbai 450
5 Sanya XII 08-10-1995 F Delhi 369
6 Mahi XI 12-12-1994 F Delhi 250
7 Neha X 08-12-1995 F Lucknow 377
8 Nishant X 12-06-1995 M Lucknow 489
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;
iii) To display those Student whose name start with ‘S’
SELECT NAME FROM STUDENT WHERE NAME LIKE “S%”;
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.