Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Split Up of XII IP Practical 2023-24 Solution

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

KENDRIYA VIDYALAYA AFS MANAURI, PRAYAGRAJ

LIST OF PRATICALS
Class-XII
Subject- Informatics Practices (065)
APRIL-MAY

1. Create a panda’s series from a dictionary of values where dictionary having


month name as key and monthly income as value. 21-04-2023
Solution-
'''Create a panda’s series from a dictionary of values where dictionary
having month name as key and monthly income as value.'''
import pandas as pd
D={'jan':25000,'feb':22300,'mar':22000,'apr':19000,'may':17400,'jun':80000,
'jul':34000,'aug':45000,'sep':40000,'oct':25000,'nov':20000,'dec':10000}
S=pd.Series(D)
print(S)
Input/Output-

2. Create a panda’s series from a ndaray where ndarayhaving marks of 5


subjects. 22-04-2023
SOLUTION:
import pandas as pd
import numpy as np
L=[]
print("Enter Marks of 5 subject : ")
for i in range(1,6):
mark=int(input("Subject"+str(i)+": "))
L.append(mark)
Marks=np.array(L)
S=pd.Series(Marks)
print(S)

INPUT/OUTPUT 1:

INPUT/OUTPUT 2:

3. Given a Series of marks, print all the elements that are above 75 marks.
05-05-2023
SOLUTION:
import pandas as pd
D={'12C01':80, '12C02':60,'12C03':88,'12C04':50,'12C05':60,'12C06':90,
'12C07':75}
S=pd.Series(D)
print(S[S>75])

INPUT/OUTPUT :
JUNE
4. Number of students in classes 11 and 12 in three streams (‘Science’,
‘Commerce’ and ‘Humanities’) are stored in two Series objects c11 and
c12. Calculate and display total number of students in classes 11 and 12,
stream wise. 02/06/2023

SOLUTION:
import pandas as pd
C11=pd.Series(data=[30,40,50],index=['Science','Commerce',
'Humanities'])
C12=pd.Series(data=[37,44,45],index=['Science','Commerce',
'Humanities'])
print("Total no. of students : ")
print(C11+C12)
INPUT/OUTPUT:

5. Create a Series Population and AvgIncome where Population stores the


details of population in four metro cites of India and AvgIncome stores the
total average income reported in previous year in each of these metors.
Calculate income per capita for each of these metro cities.
02/06/2023
SOLUTION:
import pandas as pd
Population=pd.Series(data=[13059630,14507849,54896570,39058762],\
index=['Delhi','Mumbai','Kolkata','Chennai'])
AvgIncome=pd.Series(data=[729865784756,8596756234544,\
459857586793, 895859757681], \
index=['Delhi','Mumbai','Kolkata','Chennai'])
perCapita=AvgIncome/Population
print('Population in four metro cities')
print(Population)
print('Avg. Income in four metro cities')
print(AvgIncome)
print('Per Capita Income in four metro cities')
print(perCapita)

INPUT/OUTPUT:

6. Create a Series that stores the area of some states (atleast 10) in km2.
Write code to find out the biggest and smallest three areas from the Series.
Also print series in ascending order of its value(area). 03/06/2023
SOLUTION:
import pandas as pd
STAR={'AP':162975,'MH':307713,'CH':135191,
'RJ':342239,'TN':130058,\
'MP':308245, 'UP':240928,'GJ':196024,'BR':94163, 'KA':191791,\
'AS':78438,'WB':88752}
Ser1=pd.Series(STAR)
print('States with their area are as follows : \n',Ser1)
print("Top 3 biggest areas are : ")
print(Ser1.sort_values(ascending=False).head(3))
print("Three smallest areas are : ")
print(Ser1.sort_values().head(3))
print('States with Areas (Ascending order of Areas) :')
print(Ser1.sort_values())

INPUT/OUTPUT:
States with their area are as follows :
AP 162975
MH 307713
CH 135191
RJ 342239
TN 130058
MP 308245
UP 240928
GJ 196024
BR 94163
KA 191791
AS 78438
WB 88752
dtype: int64
Top 3 biggest areas are :
RJ 342239
MP 308245
MH 307713
dtype: int64
Three smallest areas are :
AS 78438
WB 88752
BR 94163
dtype: int64
States with Areas (Ascending order of Areas) :
AS 78438
WB 88752
BR 94163
TN 130058
CH 135191
AP 162975
KA 191791
GJ 196024
UP 240928
MH 307713
MP 308245
RJ 342239
dtype: int64
JULY
7. Create a Data Frame quarterly sales where each row contains the item category, item
name, and expenditure. Group the rows by the category and print the total expenditure
per category. 01-07-2023
SOLUTION:
import pandas as pd
Sales_data={"Item_category":['Food','Drink','Food','Sweet','Food','Sweet','
Drink'],
'Item_name':['Chole','Pepsi','Paneer','Ladoo','Rajma','Kaju-Katli','Cold
Coffee'], "Expenditure":[350,60,250,200,450,300,150]}
Df_sales=pd.DataFrame(Sales_data,
index=['Item1','Item2','Item3','Item4','Item5','Item6','Item7'])
print(Df_sales)
NewDf=Df_sales.groupby('Item_category')
ExpDf=NewDf['Expenditure'].sum()
print(ExpDf)
INPUT/OUTPUT

8. Create a data frame for examination result and display row labels, column labels data
types of each column and the dimensions. 01-07-2023
SOLUTION:
import pandas as pd
marks={'Eng':[35,38,40,42,33], 'Acc':[48,43,38,34,30], 'Bst':[37,32,30,37,41],\
'Eco':[48,43,38,34,30],'IP':[35,32,31,30,28],'Total':[188,193,177,193,156],\
'Percentage':[75.2,77.2,70.8,77.2,62.4]}
result=pd.DataFrame(marks,index=['Rakesh','Sanjay','Neelima','Santosh','
Chandni'])
print(result)
print("****************Row Label****************")
print(result.index)
print("****************Column Label****************")
print(result.columns)
print("****************Dimension****************")
print(result.ndim)
print("****************Datatypes of each columns****************")
print(result.dtypes)
print("****************Shape****************")
print(result.shape)
INPUT/OUTPUT

9. Write a program to create a Data Frame Quarterly Sales where each row contains
the Quarterly Sales of TV, Freeze and AC. Show the DataFrame after deleting details
of Freeze. 07-07-2023
SOLUTION:
import pandas as pd
import numpy as np
s1=pd.Series([280,400,976], index=['TV','Freeze','AC'])
s2=pd.Series([300,233,198],index=['TV','Freeze','AC'])
s3=pd.Series([323,315,206],index=['TV','Freeze','AC'])
s4=pd.Series([279,722,298],index=['TV','Freeze','AC'])
df=pd.DataFrame([s1,s2,s3,s4],index=['QTR1','QTR2','QTR3','QTR4'])
print("Quarterly Sales : ")
print(df)
df=df.drop(['Freeze'],axis=1)
print("Quarterly Sales without detail of Freeze : ")
print(df)
INPUT/OUTPUT:

10.Create a data frame of students’ marks with name of student as label of index and
subject as column index. Display subject wise sum of marks. 14-07-2023
SOLUTION:
import pandas as pd
import numpy as np
s1=pd.Series([28,40,36, 44, 39], index=['ENG','ACC','BST', 'ECO', 'IP'])
s2=pd.Series([30,33,19,23,38],index=['ENG','ACC','BST', 'ECO', 'IP'])
s3=pd.Series([32,31,20, 34,45],index=['ENG','ACC','BST', 'ECO', 'IP'])
s4=pd.Series([27,22,29,44,38],index=['ENG','ACC','BST', 'ECO', 'IP'])
s5=pd.Series([20,43,36, 44, 39], index=['ENG','ACC','BST', 'ECO', 'IP'])
s6=pd.Series([30,33,29,23,38],index=['ENG','ACC','BST', 'ECO', 'IP'])
s7=pd.Series([32,31,26, 34,45],index=['ENG','ACC','BST', 'ECO', 'IP'])
s8=pd.Series([27,42,29,44,28],index=['ENG','ACC','BST', 'ECO', 'IP'])
df=pd.DataFrame([s1,s2,s3,s4,s5,s6,s7,s8],index=['ABHI','BIMLESH','CHETAN',\
'DINESH','CHETNA','VISHAL','RAKESH','MUKESH'])
print(df)
print("Subject wise sum of marks are : ")
print(df.sum())
INPUT/OUTPUT:
11.Create a dataframe of students’ marks with name of student as label of index and
subject as column index. Calculate and display student wise marks and percentage
scored. 14-07-2023
SOLUTION:
import pandas as pd
#Creating Data Frame
s1=pd.Series([28,40,36, 44, 39], index=['ENG','ACC','BST', 'ECO', 'IP'])
s2=pd.Series([30,33,19,23,38],index=['ENG','ACC','BST', 'ECO', 'IP'])
s3=pd.Series([32,31,20, 34,45],index=['ENG','ACC','BST', 'ECO', 'IP'])
s4=pd.Series([27,22,29,44,38],index=['ENG','ACC','BST', 'ECO', 'IP'])
s5=pd.Series([20,43,36, 44, 39], index=['ENG','ACC','BST', 'ECO', 'IP'])
df=pd.DataFrame([s1,s2,s3,s4,s5],index=['ABHI','BIMLESH','CHETAN','DINESH','CHETNA'])
print(df)
#Displaying Student wise marks and percentage scored
for (name,marks) in df.iterrows():
TotalM=sum(marks)
per=TotalM/2.5
print("Marks scored by",name,"are :")
print("Eng:",marks[0],"Acc.:",marks[1],"BST :",marks[2],'Eco :',marks[3],'IP :',marks[4])
print('Total Marks : ',TotalM,"Percentage Scored : ",per)
INPUT/OUTPUT:
12. Create the following DataFrame Sales containing year wise sales figures for five
salespersons in INR. Use the years as column labels, and salesperson names as row
labels. 15-07-2023

2018 2019 2020 2021


Kapil 110 205 177 189
Kamini 130 165 175 190
Shikhar 115 206 157 179
Mohini 118 198 183 169
a) Create the DataFrame.
b) Display the row labels of Sales.
c) Display the column labels of Sales.
d) Display the data types of each column of Sales.
e) Display the dimensions, shape, size and values of Sales.
SOLUTION:
import pandas as pd
#a)Creating Data Frame
s1=pd.Series([110,205,177,189],index=['2018','2019','2020','2021'])
s2=pd.Series([130,165,175,190],index=['2018','2019','2020','2021'])
s3=pd.Series([115,206,157,179],index=['2018','2019','2020','2021'])
s4=pd.Series([118,198,183,169],index=['2018','2019','2020','2021'])
df=pd.DataFrame([s1,s2,s3,s4],index=['Kapil','Kamini','Shikhar','Mohini'])
print(df)
#b)Display the row labels of Sales
print('Row Labels are : ', df.index.values)
#c)Display the column labels of Sales.
print('Column Labels are : ', df.columns.values)
#d)Display the data types of each column of Sales.
print('Datatype of each column are:\n', df.dtypes)
#e)Display the dimensions, shape, size and values of Sales.
print('No. of Dimensions:',df.ndim,'\nShape:',df.shape,'\nSize:',df.size,'\nValues:',df.values)
INPUT/OUTPUT:

AUGUST
13. Consider above dataframe and write code to do the following:
a) Display the last two rows of Sales.
b) Display the first two columns of Sales.
04-08-2023
SOLUTION:
import pandas as pd
#Creating Data Frame
s1=pd.Series([110,205,177,189],index=['2018','2019','2020','2021'])
s2=pd.Series([130,165,175,190],index=['2018','2019','2020','2021'])
s3=pd.Series([115,206,157,179],index=['2018','2019','2020','2021'])
s4=pd.Series([118,198,183,169],index=['2018','2019','2020','2021'])
df=pd.DataFrame([s1,s2,s3,s4],index=['Kapil','Kamini','Shikhar','Mohini'])
print("Sales Detail\n",df)
#a)Display the last two rows of Sales.
print("Last two rows of Sales detail as follows : ")
print(df.tail(2))
#b)Display the first two columns of Sales.
print("First two columns of Sales detail as follows : ")
print(df.loc[:,'2018':'2019'])
INPUT/OUTPUT:

14.Use above dataframe and do the following:


a) Change the DataFrame Sales such that it becomes its transpose.
b) Display the sales made by all sales persons in the year 2018.
c) Display the sales made by Kapil and Mohini in the year 2019 and 2020.
d) Add data to Sales for salesman Nirali where the sales made are
[221, 178, 165, 177, 210] in the years [2018, 2019, 2020, 2021] respectively
e) Delete the data for the year 2018 from the DataFrame Sales.
f) Delete the data for sales man Shikhar from the DataFrame Sales.
g) Change the name of the salesperson Kamini to Rani and Kapil to Anil.
h) Update the sale made by Mohini in 118 to 150 in 2018.
05-08-2023
SOLUTION:
import pandas as pd
#Creating Data Frame
s1=pd.Series([110,205,177,189],index=['2018','2019','2020','2021'])
s2=pd.Series([130,165,175,190],index=['2018','2019','2020','2021'])
s3=pd.Series([115,206,157,179],index=['2018','2019','2020','2021'])
s4=pd.Series([118,198,183,169],index=['2018','2019','2020','2021'])
df=pd.DataFrame([s1,s2,s3,s4],index=['Kapil','Kamini','Shikhar','Mohini'])
print("Sales Detail\n",df)
#a)Change the DataFrame Sales such that it becomes its transpose.
print("Transpose of Sales : ")
print(df.T)
#b)Display the sales made by all sales persons in the year 2018.
print("Sales made by salesperson in year 2018 : ")
print(df['2018'])
#c)Display the sales made by Kapil and Mohini in the year 2019 and 2020.
print("Sales made by Kapil and Mohini in 2019 and 2020 : ")
df1=df[['2019','2020']]
print(df1.loc['Kapil':'Kapil',])
print(df1.loc['Mohini':'Mohini',])
#d)Add data to Sales for salesman Nirali where the sales made are
#[221, 178, 165, 177] in the years [2018, 2019, 2020, 2021] respectively
print("Sales detail after adding one more row of Salesperson Nirali :")
df.loc['Nirali',]=[221,178,165,177]
print(df)
#e)Update the sale made by Mohini in 118 to 150 in 2018.
df.loc['Mohini','2018']=150
print("Sales detail after modifying data of Mohini for year 2018:")
print(df)
#f)Delete the data for the year 2018 from the DataFrame Sales.
df=df.drop(['2018'],axis=1)
print("Sales detail after deleting data for year 2018:")
print(df)
#g)Delete the data for salesman Shikhar from the DataFrame Sales.
df=df.drop(['Shikhar'])
print("Sales detail after deleting data of Shikhar:")
print(df)
#h)Change the name of the salesperson Kamini to Rani and Kapil to Anil.
df.rename({'Kamini':'Rani','Kapil':'Anil'},inplace=True)
print("Sales detail with modified salesperson name :")
print(df)
INPUT/OUTPUT:
15.Write a program to input and create a DataFrame to store Roll Number, Name and
percentage of five students and write above data frame in a csv file “marks.csv”.
SOLUTION: 12-08-2023
import pandas as pd
L=[]
for i in range(1,6):
rn=int(input('Enter Roll no. of student '+str(i)+' : '))
nm=input('Enter Name of student '+str(i)+' : ')
mks=int(input('Enter Marks of student '+str(i)+' : '))
L1=[rn,nm,mks]
L.append(L1)
df=pd.DataFrame(L,columns=['Rollno','Name','Marks'])
print('Data Frame for the student detail as follows:')
print(df)
df.to_csv('C:\\Python3.9\\marks.csv')
print('marks.csv file created successfully!')
INPUT/OUTPUT:
16. Write a program to read “marks.csv” file and display student details in the following
format-
Roll no: XXXXX
Name: abcd
Percentage Scored: XXX.XX
.
.
Total Student:XX
Average Percentage:XXX.XX

SOLUTION:
import pandas as pd
df=pd.read_csv('C:\\Python3.9\\marks.csv',header=None,skiprows=1,names=['Roll','Nam
e','Marks'])
ts=0
print(df)
for (row,data) in df.iterrows():
print('Roll no:',data[0])
print('Name:',data[1])
print('Percentage Scored:',data[2])
ts=ts+1
print('Total Student:',ts)
print('Average Percentage:',df['Marks'].sum()/ts)

INPUT/OUTPUT:

17.Plot the following data on a line chart and customize the chart according to
the below-given instructions:
Sales Report
Month January February March April May
Sales 510 350 475 580 600

1. Write a title for the chart “The Monthly Sales Report“


2. Write the appropriate titles of both the axes
3. Write code to Display legends
4. Display blue color for the line
5. Use the line style – dashed
6. Display diamond style markers on data points.
SOLUTION:
import pandas as pd
import matplotlib.pyplot as plt
Month=['January','February','March','April','May']
Sales=[510,350,475,580,600]
plt.plot(Month,Sales,linestyle='dashed',marker='d',color='b',label='Month wise Sale')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.title('The Monthly Sales Report')
plt.legend()
plt.show()
OUTPUT:

18.Pratyush Garments has recorded the following data into their register for their income
from cotton clothes and jeans. Plot them on the line chart.
Day Monday Tuesday Wednesday Thursday Friday
Cotton 450 560 400 605 580
Jeans 490 600 425 610 625
Apply following customization to the line chart.
1. Write a title for the chart “The Weekly Garment Orders”.
2. Write the appropriate titles of both the axes.
3. Write code to Display legends.
4. Display your choice of colors for both the lines cotton and jeans.
5. Use the line style – dotted for cotton and dashdot for jeans.
6. Display plus markers on cotton and x markers of jeans.
SOLUTION:
import pandas as pd
import matplotlib.pyplot as plt
weekday=['Monday','Tuesday','Wednesday','Thursday','Friday']
Cotton=[450,560,400,605,580]
Jeans=[490,600,425,610,625]
plt.plot(weekday,Cotton,linestyle='dotted',marker='+',color='b',label='Cotton')
plt.plot(weekday,Jeans,linestyle='dashdot',marker='x',color='r',label='Jeans')
plt.xlabel('Day')
plt.ylabel('Sale of Cotton Clothes and Jeans')
plt.title('The Weekly Garment Orders')
plt.legend()
plt.show()
INPUT/OUTPUT:
SEPTEMBER

19. TSS school celebrated volunteering week where each section of class XI dedicated a day
for collecting amount for charity being supported by the school. Section A volunteered
on Monday, B on Tuesday, C on Wednesday and so on. There are six sections in class XI.
Amounts collected by sections A to F are 8000, 12000, 9800, 11200, 15500, 7300.
a. Write a program to create a bar chart showing collection amount.
b. The graph should have proper title and axes titles.
c. The ticks on X-axis should have Day Names.

SOLUTION:

import pandas as pd
import matplotlib.pyplot as plt
weekday=['Mon','Tue','Wed','Thu','Fri','Sat']
Coll=[8000, 12000, 9800, 11200, 15500, 7300]
Jeans=[490,600,425,610,625]
plt.bar(weekday,Coll,color='r', width=0.25)
plt.xlabel('Days')
plt.ylabel('Collection')
plt.title('Volunteering Week Collection')
plt.xticks(weekday)
plt.show()

INPUT/OUTPUT:
20.Display comparison of Run Scored by two teams in a cricket match using bar charts on
the same plane with following features:

RunTeam
Over RunTeamA B
5 26 30

10 23 28

15 30 22

20 50 40
a. Write a program to create a bar chart showing bars for teamA and teamB side by
side.
b. Use red color for bars of TeamA and blue for bars of TeamB
c. The graph should have proper title and axes titles.
d. The ticks on X-axis should have Overs.

SOLUTION:
import numpy as np
import matplotlib.pyplot as plt
Over=np.array([4,8,12,16,20])
RunTeamA=[26,23,30,40,34]
RunTeamB=[30,28,22,50,40]
plt.bar(Over,RunTeamA,color='r', width=0.5)
plt.bar(Over+0.5,RunTeamB,color='b', width=0.5)
plt.xlabel('Over')
plt.ylabel('Run')
plt.title('Over wise Run')
plt.xticks(Over)
plt.show()
INPUT/OUTPUT:
21.A survey gathers height and weight of 100 participants and recorded the participants’
ages (assume any 100 values, each value must be between 1 to 100, you can repeat values
as many times you wish).
Write a program to plot a histogram from above data with 20 bins.
SOLUTION:
import numpy as np
import matplotlib.pyplot as plt
ages=[1,1,2,3,4,7,8,9,10,10,10,11,13,13,13,13,15,16,17,18,19,19,20,20,20,\
23,23,24,24,24,24,25,25,25,25,25,25,25,25,27,27,27,28,28,29,30,30,30,40,\
40,42,42,43,50,50,50,51,52,55,57,57,58,58,58,60,60,60,63,63,70,70,70,70,\
70,73,73,73,73,74,76,76,77,79,80,83,85,85,88,89,89,89,90,91,94,94,94,94,96,97,97]
plt.hist(ages, bins=20)
plt.hist(ages, bins=20)
plt.xlabel('age ranges')
plt.ylabel('No of participants')
plt.title('Participants\' Age Histogram')
plt.show()
INPUT/OUTPUT:

OCTOBER
Q.22.Consider the following table PRODUCT-
PRODUCT
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) Write MySQL commands for following Statements
i. To show details of all PC with stock more than 110.
ii. To list the company which gives warranty for more than 2 years?
iii. To find stock value of the BPL Company where stock value is sum of the products of
price and stock.
iv. To show number of products from each company.
v. To count the number of PRODUCTS which are manufactured in 2009?
vi. To show the PRODUCT name which are within warranty as on date?
(b) Give the output of following MySQL statement.
(i) Select COUNT (distinct company) from PRODUCT;
(ii) Select MAX (price) from PRODUCT where WARRANTY<=3;
(iii) Select AVG(price) from PRODUCT where Company=”SONY”;
(iv) Select MIN(price) from PRODUCT where stock<200;
ANSWER:
(a)
i. SELECT * FROM PRODUCT WHERE PNAME=’PC’ AND STOCK>110;
ii. SELECT COMPANY FROM PRODUCT WHERE WARRANTY>2;
iii. SELECT SUM(STOCK*PRICE) AS “STOCK VALUE” FROM PRODUCT WHERE COMPANY=’BPL’;
iv. SELECT COMPANY,COUNT(*) “NO OF PRODUCT” FROM PRODUCT GROUP BY COMPANY;
v. SELECT COUNT(*) “NO OF PRODUCT MANUFACTURED IN 2009” FROM PRODUCT WHERE
YEAR(MANUFACTURE)=2009;
vi. SELECT PNAME FROM PRODUCT WHERE TRUNCATE(DATEDIFF(CURDATE(),MANUFACTURE)/
365,0)>WARRANTY;
(b)
(i)

(ii)

(iii)

(iv)
Q.23. Study the following table STUDENT and write MySQL command for the questions (i)
to (vii)
TABLE: STUDENT
SID Name Stream Gende Marks
r
101 Siddharat Science M 42
104 Raghav Science M 26
107 Naman Commerce M 40
114 Nupur Humanities F 13
109 Janvi Commerce F 19
105 Rama Humanities M 30
117 James Science F 23
111 Binoy Science F 12
130 Samuel Commerce M 45

i.Create a student table with the student id, name, Stream, gender and marks as
attributes where the student id is the primary key.
ii. Insert the details of students as given in the above table.
iii. Delete the details of students whose name starts with letter ‘B’.
iv. Display the details of the students with marks more than 80.
v. Find the min, max, sum, and average of the marks in a student marks table.
vi. Find the total number of students stream wise.
vii. Display the Name and Marks of Students in descending order of the marks.

SOLUTION:
i. CREATE TABLE STUDENT(SID INT NOT NULL PRIMARY KEY, NAME VARCHAR(20),
STREAM VARCHAR(20), GENDER CHAR(1),MARKS INT);
ii. INSERT INTO STUDENT VALUES(101,'Siddharat','Science','M',42);
INSERT INTO STUDENT VALUES(104,'Raghav','Science','M',26);
INSERT INTO STUDENT VALUES(107,'Naman','Commerce','M',40);
INSERT INTO STUDENT VALUES(114,'Nupur','Humanities','F',13);
INSERT INTO STUDENT VALUES(109,'Janvi','Commerce','F',19);
INSERT INTO STUDENT VALUES(105,'Rama','Humanities','M',30);
INSERT INTO STUDENT VALUES(117,'James','Science','F',23);
INSERT INTO STUDENT VALUES(111,'Binoy','Science','F',12);
INSERT INTO STUDENT VALUES(130,'Samuel','Commerce','M',45);
iii. Delete FROM STUDENT WHERE NAME LIKE “B%”;
iv. SELECT * FROM STUDENT WHERE MARKS>80;
v. SELECT MIN(MARKS), MAX(MARKS), SUM(MARKS), AVG(MARKS) FROM STUDENT;
vi. SELECT STREAM, COUNT(*) FROM STUDENT GROUP BY STREAM;
vii. SELECT NAME, MARK FROM STUDENT ORDER BY MARKS DESC;
Q.24. Answer the following questions based on the table CLUB given below:
TABLE :CLUB
Column Name Data Siz Constraints Description
Type e
Member_No Number 5 Primary Member number
Member_Name Varchar2 40 Key Name of the member
Address Varchar2 30 Not Null Address of he member
Age Number 2 Age of the member
Type Varchar2 10 >=18 Membershiptype(Temp or Permanent)
Fees Number 6,2 Membership fees

a) Write the SQL command to create the table CLUB including the constraints.
b) Insert two tuples.
c) Write the SQL command to display the details of all the members whose type is “Permanent”
and fees is more than Rs. 5000.
d) Write SQL query to add a new column called Phno.
e) Change the fees rate by 10% if the membership is of type “Temp”
f) Write the SQL command to display all the details of all the members whose age is greater than
eighteen.
Write the output of the following SQL queries:
a) SELECT ROUND(6.5675, 2);
b) SELECT TRUNCATE(5.3456, 1);
c) SELECT DAYOFMONTH('2009-08-25');
d) SELECT MID('Class 12', 2,3);
ANSWER:
a) CREATE TABLE CLUB(Member_No int(5) not null primary key, Member_Name varchar(40) not null,
Address varchar(30), Age int(2), Type varchar(10), Fees Numeric(6,2), check (Age>=18));

b)

c) SELECT * FROM CLUB WHERE TYPE=’PERMANENT’ AND FEES>5000;


d) ALTER TABLE CLUB ADD PHNO INT;
e) UPDATE CLUB SET FEES=FEES*0.1 WHERE MEMBERSHIP=’TEMP’;
f) SELECT * FROM CLUB WHERE AGE>18;
OUTPUTS
Q.25. Consider the table TEACHER given below. Write commands in SQL for (i) to (iv) and
output for (v) to (viii)
TEACHER
ID Name Department Hiredate Category Gender Salary
1 Tanya Nanda SocialStudies 1994-03-17 TGT F 25000
2 Saurabh Sharma Art 1990-02-12 PRT M 20000
3 Nandita Arora English 1980-05-16 PGT F 30000
4 James Jacob English 1989-10-16 TGT M 25000
5 Jaspreet Kaur Hindi 1990-08-01 PRT F 22000
6 Disha Sehgal Math 1980-03-17 PRT F 21000
7 Siddharth Kapoor Science 1994-09-02 TGT M 27000
8 Sonali Mukherjee Math 1980-11-17 TGT F 24500
i. Display details of oldest teacher.
ii. Display total salary of Female employee Category wise.
iii. To list names, departments and date of hiring of all the teachers in ascending order of date
of joining
iv. To count the number of teachers department wise.
v. SELECT MAX(Hiredate) FROM Teacher;
vi. SELECT DISTINCT(category) FROM teacher;
vii. SELECT COUNT(*) FROM TEACHER WHERE Category = "PGT"
viii. SELECT AVG(Salary) FROM TEACHER group by Gender;

SOLUTIONS:

You might also like