Professional Documents
Culture Documents
Kendriya Vidyalaya Painavu, Idukki: Class Xii - Term 2 Lab Record
Kendriya Vidyalaya Painavu, Idukki: Class Xii - Term 2 Lab Record
PAINAVU, IDUKKI
1
Index
2
Expt No:1 Date: 22/01/2022
Program:
def isempty(stk):
if stk==[]:
return True
else:
return False
def push(stk,item):
stk.append(item)
top=len(stk)-1
def peek(stk):
if isempty(stk):
return "UnderFlow"
else:
top=len(stk)-1
return stk[top]
def pop(stk):
if isempty(stk):
return "Underflow"
else:
item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
3
def Display(stk):
if isempty(stk):
print("Underflow! Stack is empty")
else:
top=len(stk)-1
print(stk[top],"<-- top")
for a in range(top-1,-1,-1):
print(stk[a])
Stack=[]
top=None
while True:
print("Stack Operations")
print("1. Push")
print("2. Pop")
print("3. Display")
print("4. Peek")
print("5. Exit")
ch=int(input("Enter your choice(1-5): "))
if ch==1:
item=input("enter the item to pushed: ")
push(Stack,item)
print("Satck after Push",Stack)
elif ch==2:
item=pop(Stack)
if item=="Underflow":
print("Underflow! Stack is empty")
else:
print("Popped item is",item)
print("Stack after Pop",Stack)
elif ch==3:
Display(Stack)
elif ch==4:
print(peek(Stack))
elif ch==5:
break
else:
print("Wrong Choice")
4
Output:
Stack Operations
1. Push
2. Pop
3. Display
4. Peek
5. Exit
5
Satck after Push ['23', '56', '87', '65']
Stack Operations
1. Push
2. Pop
3. Display
4. Peek
5. Exit
6
Enter your choice(1-5): 3
87 <-- top
56
23
Stack Operations
1. Push
2. Pop
3. Display
4. Peek
5. Exit
Result:
7
Expt No:2 Date: 22/01/2022
Julie has created a dictionary containing names and marks as key value pairs of 6 students. Write a
program, with separate user defined functions to perform the following operations:
Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
(marks) is greater than 75.
Pop and display the content of the stack.
Program:
def display(stk):
print("current stack contents")
for i in range(-1,-len(stk)-1,-1):
if i==-1:
print(stk[i],"<---top",sep="")
else:
print(stk[i])
print()
def spop(stk):
while len(stk)!=0:
item=stk.pop()
print("popped item is",item)
display(stk)
else:
print("stack empty")
spush(stk,R)
display(stk)
spop(stk)
8
Output:
TOM<---top
ANU
BOB
OM
ANU<---top
BOB
OM
BOB<---top
OM
OM<---top
popped item is OM
stack empty
9
Expt No:3 Date: 22/01/2022
Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the following operations based on this list.
Traverse the content of the list and push the even numbers into a stack.
Pop and display the content of the stack.
For Example:
If the sample Content of the list is as follows: N = [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Program:
N = [12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
stk=[]
def spush(stk,inp):
for k in inp:
if k%2==0:
stk.append(k)
def display(stk):
print("current stack contents")
for i in range(-1,-len(stk)-1,-1):
if i==-1:
print(stk[i],"<---top",sep="")
else:
print(stk[i])
print()
def spop(stk):
while len(stk)!=0:
item=stk.pop()
print("popped item is",item)
display(stk)
else:
print("stack empty")
spush(stk,N)
display(stk)
spop(stk)
10
Output:
popped item is 38
current stack contents
22<---top
98
56
34
12
popped item is 22
current stack contents
98<---top
56
34
12
popped item is 98
current stack contents
56<---top
34
12
popped item is 56
current stack contents
34<---top
12
popped item is 34
current stack contents
12<---top
popped item is 12
current stack contents
stack empty
Create a student table with following details and populate the table with data given below.
Program:
12
mysql> desc student;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| adno | int | YES | | NULL | |
| sname | char(20) | YES | | NULL | |
| gender | char(1) | YES | | NULL | |
| class | char(5) | YES | | NULL | |
| mark | int | YES | | NULL | |
| height | int | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
6 rows in set (0.05 sec)
13
mysql> select * from student;
+------+----------+--------+-------+------+--------+
| adno | sname | gender | class | mark | height |
+------+----------+--------+-------+------+--------+
| 1001 | abhishek | M | XII | 95 | 170 |
| 1002 | alen | M | XI | 90 | 172 |
| 1003 | althaf | M | X | 91 | 168 |
| 1004 | amita | F | XII | 92 | 165 |
| 1005 | devanand | M | XI | 85 | 160 |
| 1006 | margret | F | IX | 96 | 163 |
| 1007 | nayana | F | XI | 95 | 165 |
| 1008 | sreehari | M | XII | 90 | 160 |
+------+----------+--------+-------+------+--------+
8 rows in set (0.00 sec)
14
Expt No:5 Date: 22/01/2022
Program:
15
mysql> SELECT * FROM STUDENT;
+------+----------+--------+-------+------+--------+------+
| adno | sname | gender | class | mark | height | DOB |
+------+----------+--------+-------+------+--------+------+
| 1001 | abhishek | M | XII | 95 | 170 | NULL |
| 1002 | alen | M | XI | 90 | 172 | NULL |
| 1003 | althaf | M | X | 91 | 168 | NULL |
| 1004 | amita | F | XII | 92 | 165 | NULL |
| 1005 | devanand | M | XI | 85 | 160 | NULL |
| 1006 | margret | F | IX | 96 | 163 | NULL |
| 1007 | nayana | F | XI | 95 | 165 | NULL |
| 1008 | sreehari | M | XII | 90 | 160 | NULL |
+------+----------+--------+-------+------+--------+------+
8 rows in set (0.01 sec)
16
mysql> DESC STUDENT;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| adno | int | YES | | NULL | |
| sname | char(20) | YES | | NULL | |
| gender | char(1) | YES | | NULL | |
| class | char(5) | YES | | NULL | |
| mark | int | YES | | NULL | |
| height | int | YES | | NULL | |
| DOB | date | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
7 rows in set (0.02 sec)
17
mysql> SELECT * FROM STUDENT;
+------+----------+--------+-------+------+--------+------------+
| adno | sname | gender | class | mark | height | DOB |
+------+----------+--------+-------+------+--------+------------+
| 1001 | abhishek | M | XII | 95 | 170 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 172 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 168 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 165 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 160 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 163 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 165 | 2003-01-01 |
| 1008 | sreehari | M | XII | 90 | 160 | 2003-01-01 |
+------+----------+--------+-------+------+--------+------------+
8 rows in set (0.00 sec)
18
mysql> DESC STUDENT;
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| adno | int | YES | | NULL | |
| sname | varchar(20) | YES | | NULL | |
| gender | char(1) | YES | | NULL | |
| class | char(5) | YES | | NULL | |
| mark | int | YES | | NULL | |
| DOB | date | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
19
Expt No:6 Date: 22/01/2022
Write an SQL query to display the student records based on their names in in ascending / descending
order.
Program:
20
mysql> SELECT * FROM STUDENT ORDER BY SNAME DESC;
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1008 | sreehari | M | XII | 90 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 2003-01-01 |
| 1001 | abhishek | M | XII | 95 | 2003-01-01 |
+------+----------+--------+-------+------+------------+
8 rows in set (0.00 sec)
21
Expt No:7 Date: 22/01/2022
Write an SQL query to insert the following records into the student table.
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1009 | cebil | M | XI | 99 | 2003-09-12 |
| 1010 | helen | F | IX | 98 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
Program:
22
Expt No:8 Date: 22/01/2022
Write an SQL query to delete the students whose mark is 98 or above from the student table given
below.
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 95 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 2003-01-01 |
| 1008 | sreehari | M | XII | 90 | 2003-01-01 |
| 1009 | cebil | M | XI | 99 | 2003-09-12 |
| 1010 | helen | F | IX | 98 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
Program:
23
Expt No:9 Date: 22/01/2022
Write an SQL query to find the following details from the student table given below.
To find the highest scorer in each class.
To find the low performer in each class.
To find the total marks in each class.
To find the no of students in each class.
To find the average marks in each class.
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 95 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 2003-01-01 |
| 1008 | sreehari | M | XII | 90 | 2003-01-01 |
| 1009 | cebil | M | XI | 99 | 2003-09-12 |
| 1010 | helen | F | IX | 98 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
Program:
24
-> FROM STUDENT GROUP BY class;
+------+----------+-------+------------+------------+
| adno | sname | class | lowestmark | dob |
+------+----------+-------+------------+------------+
| 1001 | abhishek | XII | 90 | 2003-01-01 |
| 1002 | alen | XI | 85 | 2003-01-01 |
| 1003 | althaf | X | 91 | 2003-01-01 |
| 1006 | margret | IX | 96 | 2003-01-01 |
+------+----------+-------+------------+------------+
4 rows in set (0.01 sec)
25
mysql> SELECT class,avg(mark) as class_average
-> FROM student GROUP BY class;
+-------+---------------+
| class | class_average |
+-------+---------------+
| XII | 92.3333 |
| XI | 92.2500 |
| X | 91.0000 |
| IX | 97.0000 |
+-------+---------------+
4 rows in set (0.00 sec)
26
Expt No:10 Date: 22/01/2022
Write an SQL query to find the following details from the student table given below.
a) To display eno, ename, salary and corresponding dept_name of all the employees.
b) To display eno, ename, salary and corresponding dept_name of all the employees whose age is between
25 and 35 (both values inclusive).
c) To display dept_name and corresponding ename from the tables DEPARTMENT and EMPLOYEE,
(Hint’ HOD of the DEPARTMENT table should be matched with eno of the EMPLOYEE table for
getting the desired result).
d) To display ename, salary, zone and income tax (Note income tax to be calculated as 30% of salary) of
all the employees with appropriate column headings.
Table Description: employee
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| eno | int | NO | PRI | NULL | |
| ename | varchar(20) | YES | | NULL | |
| salary | int | YES | | NULL | |
| zone | char(5) | YES | | NULL | |
| age | int | YES | | NULL | |
| grade | char(1) | YES | | NULL | |
| dept | int | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
Table Description: department
+-----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| deptno | int | NO | PRI | NULL | |
| dept_name | char(15) | YES | | NULL | |
| hod | int | YES | MUL | NULL | |
+-----------+----------+------+-----+---------+-------+
*MUL- Multiple occurrences of a given value are permitted
within the column. (i.e. Foreign Key)- here hod field refers
primary key of employee table, i.e. enono;
Table: employee
+-----+--------+--------+-------+------+-------+------+
| eno | ename | salary | zone | age | grade | dept |
+-----+--------+--------+-------+------+-------+------+
| 1 | MONA | 70000 | EAST | 40 | A | 10 |
| 2 | MUKTAR | 71000 | WEST | 45 | B | 20 |
| 3 | NALINI | 60000 | EAST | 26 | A | 10 |
| 4 | SANAJ | 65000 | SOUTH | 36 | A | 20 |
| 5 | SURYA | 58000 | NORTH | 30 | B | 30 |
+-----+--------+--------+-------+------+-------+------+
27
Table : department
+--------+-------------+------+
| deptno | dept_name | hod |
+--------+-------------+------+
| 10 | IT | 1 |
| 20 | LOAN | 2 |
| 30 | AGRICULTURE | 5 |
| 40 | LANGUAGE | 3 |
+--------+-------------+------+
Program:
a) To display eno, ename, salary and corresponding dept_name of all the employees.
OR
28
mysql> select employee.eno,employee.ename,employee.salary,
-> department.dept_name from employee inner join department
-> on employee.dept=department.deptno;
+-----+--------+--------+-------------+
| eno | ename | salary | dept_name |
+-----+--------+--------+-------------+
| 1 | MONA | 70000 | IT |
| 2 | MUKTAR | 71000 | LOAN |
| 3 | NALINI | 60000 | IT |
| 4 | SANAJ | 65000 | LOAN |
| 5 | SURYA | 58000 | AGRICULTURE |
+-----+--------+--------+-------------+
5 rows in set (0.00 sec)
OR
b) To display eno, ename, salary and corresponding dept_name of all the employees whose age is between
25 and 35 (both values inclusive).
29
c) To display dept_name and corresponding ename from the tables DEPARTMENT and EMPLOYEE.
d) To display ename, salary, zone and income tax (Note income tax to be calculated as 30% of salary) of
all the employees with appropriate column headings.
30
Expt No:11 Date: 22/01/2022
Write a python program to do the following operations on the student table (database: kvidk) given below.
a) To reduce 5 marks from mark of every student.
b) To change the date of birth of cebil to “1996-05-25”.
c) To display the class’s having 3 or more students.
Table:student
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 95 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 2003-01-01 |
| 1008 | sreehari | M | XII | 90 | 2003-01-01 |
| 1009 | cebil | M | XI | 99 | 2003-09-12 |
| 1010 | helen | F | IX | 98 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
31
Program:
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("UPDATE STUDENT SET MARK=MARK-5")
cursor.execute("SELECT * FROM STUDENT")
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
(1001, 'abhishek', 'M', 'XII', 90, datetime.date(2003, 1, 1))
(1002, 'alen', 'M', 'XI', 85, datetime.date(2003, 1, 1))
(1003, 'althaf', 'M', 'X', 86, datetime.date(2003, 1, 1))
(1004, 'amita', 'F', 'XII', 87, datetime.date(2003, 1, 1))
(1005, 'devanand', 'M', 'XI', 80, datetime.date(2003, 1, 1))
(1006, 'margret', 'F', 'IX', 91, datetime.date(2003, 1, 1))
(1007, 'nayana', 'F', 'XI', 90, datetime.date(2003, 1, 1))
(1008, 'sreehari', 'M', 'XII', 85, datetime.date(2003, 1, 1))
(1009, 'cebil', 'M', 'XI', 94, datetime.date(2003, 9, 12))
(1010, 'helen', 'F', 'IX', 93, datetime.date(2002, 10, 21))
Output(MySQL):
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 90 | 2003-01-01 |
| 1002 | alen | M | XI | 85 | 2003-01-01 |
| 1003 | althaf | M | X | 86 | 2003-01-01 |
| 1004 | amita | F | XII | 87 | 2003-01-01 |
| 1005 | devanand | M | XI | 80 | 2003-01-01 |
| 1006 | margret | F | IX | 91 | 2003-01-01 |
| 1007 | nayana | F | XI | 90 | 2003-01-01 |
| 1008 | sreehari | M | XII | 85 | 2003-01-01 |
| 1009 | cebil | M | XI | 94 | 2003-09-12 |
| 1010 | helen | F | IX | 93 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
32
Program:
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("UPDATE STUDENT SET DOB=%s WHERE SNAME=%s",("1996-05-25","CEBIL"))
cursor.execute("select * from student")
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
(1001, 'abhishek', 'M', 'XII', 90, datetime.date(2003, 1, 1))
(1002, 'alen', 'M', 'XI', 85, datetime.date(2003, 1, 1))
(1003, 'althaf', 'M', 'X', 86, datetime.date(2003, 1, 1))
(1004, 'amita', 'F', 'XII', 87, datetime.date(2003, 1, 1))
(1005, 'devanand', 'M', 'XI', 80, datetime.date(2003, 1, 1))
(1006, 'margret', 'F', 'IX', 91, datetime.date(2003, 1, 1))
(1007, 'nayana', 'F', 'XI', 90, datetime.date(2003, 1, 1))
(1008, 'sreehari', 'M', 'XII', 85, datetime.date(2003, 1, 1))
(1009, 'cebil', 'M', 'XI', 94, datetime.date(1996, 5, 25))
(1010, 'helen', 'F', 'IX', 93, datetime.date(2002, 10, 21))
Output(MySQL):
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 90 | 2003-01-01 |
| 1002 | alen | M | XI | 85 | 2003-01-01 |
| 1003 | althaf | M | X | 86 | 2003-01-01 |
| 1004 | amita | F | XII | 87 | 2003-01-01 |
| 1005 | devanand | M | XI | 80 | 2003-01-01 |
| 1006 | margret | F | IX | 91 | 2003-01-01 |
| 1007 | nayana | F | XI | 90 | 2003-01-01 |
| 1008 | sreehari | M | XII | 85 | 2003-01-01 |
| 1009 | cebil | M | XI | 94 | 1996-05-25 |
| 1010 | helen | F | IX | 93 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
33
Program:
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("select class, count(*) as strength from student group by class
having count(*)>=3")
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
('XII', 3)
('XI', 4)
Output(MySQL):
34
Expt No:12 Date: 22/01/2022
Write a python program to do the following operations on the student table (database: kvidk) given below.
a) To display the student records where student name ends with character ‘a’.
b) To delete all the student records with mark less than 90.
c) To display the average mark of class XI students.
Table:student
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 95 | 2003-01-01 |
| 1002 | alen | M | XI | 90 | 2003-01-01 |
| 1003 | althaf | M | X | 91 | 2003-01-01 |
| 1004 | amita | F | XII | 92 | 2003-01-01 |
| 1005 | devanand | M | XI | 85 | 2003-01-01 |
| 1006 | margret | F | IX | 96 | 2003-01-01 |
| 1007 | nayana | F | XI | 95 | 2003-01-01 |
| 1008 | sreehari | M | XII | 90 | 2003-01-01 |
| 1009 | cebil | M | XI | 99 | 2003-09-12 |
| 1010 | helen | F | IX | 98 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
35
Program:
a) To display the student records where student name ends with character ‘a’.
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("select * from student where sname like %s",("%a",))
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
(1004, 'amita', 'F', 'XII', 87, datetime.date(2003, 1, 1))
(1007, 'nayana', 'F', 'XI', 90, datetime.date(2003, 1, 1))
Output(MySQL):
mysql> select * from student where sname like "%a";
+------+--------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+--------+--------+-------+------+------------+
| 1004 | amita | F | XII | 87 | 2003-01-01 |
| 1007 | nayana | F | XI | 90 | 2003-01-01 |
+------+--------+--------+-------+------+------------+
2 rows in set (0.00 sec)
36
Program:
b) To delete all the student records with mark less than 90.
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("delete from student where mark<90")
cursor.execute("select * from student")
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
(1001, 'abhishek', 'M', 'XII', 90, datetime.date(2003, 1, 1))
(1006, 'margret', 'F', 'IX', 91, datetime.date(2003, 1, 1))
(1007, 'nayana', 'F', 'XI', 90, datetime.date(2003, 1, 1))
(1009, 'cebil', 'M', 'XI', 94, datetime.date(1996, 5, 25))
(1010, 'helen', 'F', 'IX', 93, datetime.date(2002, 10, 21))
Output(MySQL):
mysql> select * from student;
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 90 | 2003-01-01 |
| 1002 | alen | M | XI | 85 | 2003-01-01 |
| 1003 | althaf | M | X | 86 | 2003-01-01 |
| 1004 | amita | F | XII | 87 | 2003-01-01 |
| 1005 | devanand | M | XI | 80 | 2003-01-01 |
| 1006 | margret | F | IX | 91 | 2003-01-01 |
| 1007 | nayana | F | XI | 90 | 2003-01-01 |
| 1008 | sreehari | M | XII | 85 | 2003-01-01 |
| 1009 | cebil | M | XI | 94 | 1996-05-25 |
| 1010 | helen | F | IX | 93 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
10 rows in set (0.00 sec)
mysql> delete from student where mark<90
mysql> select * from student;
+------+----------+--------+-------+------+------------+
| adno | sname | gender | class | mark | DOB |
+------+----------+--------+-------+------+------------+
| 1001 | abhishek | M | XII | 90 | 2003-01-01 |
| 1006 | margret | F | IX | 91 | 2003-01-01 |
| 1007 | nayana | F | XI | 90 | 2003-01-01 |
| 1009 | cebil | M | XI | 94 | 1996-05-25 |
| 1010 | helen | F | IX | 93 | 2002-10-21 |
+------+----------+--------+-------+------+------------+
5 rows in set (0.00 sec)
37
Program:
if coobj.is_connected():
print('Connected')
else:
print('Failed')
cursor=coobj.cursor()
cursor.execute("select class, avg(mark) from student group by class having
class=%s",("XI",))
data=cursor.fetchall()
for i in data:
print(i)
coobj.commit()
Output(Python):
Connected
('XI', Decimal('92.0000'))
Output(MySQL):
38