IP Practical Record 2022-23
IP Practical Record 2022-23
CLASS: XII-C
CBSE ROLL NO:
SCHOOL: Kendriya Vidyalaya Cossipore
Subject: INFORMATICS PRACTICES (065) Practical Record
1
INDEX
Sl. No. Program Sign. Of
Date
Teacher
7 05-07-22 Write a program to create a dataframe and display the data using loc
Write a Program to read CSV file and show its data in python using
11 10-08-22
dataFrames and pandas.
2
Write a program in python to plot a line graph of marks obtained in
18 27-09-22
five subjects by five students
3
CERTIFICATE
Principal’s
Signature
4
LAB ACTIVITY 1 Date:05-04-22
AIM: Write a program in python to calculate the cube of the series values as given below 2,5,7,4,9
#CODE
import pandas as pd #Importing pandas module
S_data = pd.Series([2,5,7,4,9]) #Creation of Series
#Printing of Original Series data
print("Original Series data")
print(S_data)
#Calculation and Printing of cubes of all data from new Series print("Cube of Series data")
Cube_data= S_data**3
print(Cube_data)
SAMPLE OUTPUT
Original Series data
02
15
27
34
49
dtype: int64
Cube of Series data
08
1 125
2 343
3 64
4 729
dtype: int64
5
LAB ACTIVITY 2 Date:12-04-22
AIM: Write a program in python to create a series Ser1 of numeric data with labels as a, b, c, d, e.
Then create a new series object Ser2, contains squares of each values from Ser1. Display Ser2
values which are greater than 15.
#CODE
import pandas as pd #Importing pandas module
Ser1 = pd.Series([2,3,5,4,1], index=['a','b','c','d','e']) #Creation of Series Ser1
#Printing of Original Series data
print("Series Ser1 data")
print(Ser1)
Ser2= Ser1**2 #Calculation the square of Ser1 and stored in Ser1
print(Ser2[Ser2>15]) #Checking the values which are greater than 15 and printing
SAMPLE OUTPUT
Series Ser1 data
a2
b3
c5
d4
e1
dtype: int64
c 25
d 16
dtype: int64
6
LAB ACTIVITY 3 Date:19-04-22
AIM: Write a program in python to update the following series by writing code for question (i) to
(v)
Kiran 33
Manvendra 48
Saswati NaN
Yash 43
(i) Create the above Series Ser
(ii) Add a new student Dev with marks 40
(iii) Fill all missing values by 0.
(iv) Update marks of Manvendra and Saswati by 44.
(v) Display all information of Yash and Manvendra. (First display Yash then Manvendra)
#CODE
import pandas as pd
import numpy as np
7
SAMPLE OUTPUT
Output (i)
===================
Kiran 33.0
Manvendra 48.0
Saswati NaN
Yash 43.0
dtype: float64
Output (ii)
===================
Kiran 33.0
Manvendra 48.0
Saswati NaN
Yash 43.0
Dev 40.0
dtype: float64
Output (iii)
===================
Kiran 33.0
Manvendra 48.0
Saswati 0.0
Yash 43.0
Dev 40.0
dtype: float64
Output (iv)
===================
Kiran 33.0
Manvendra 44.0
Saswati 44.0
Yash 43.0
Dev 40.0
dtype: float64
Output (v)
===================
Yash 43.0
8
Manvendra 44.0
dtype: float64
AIM: Write a program in python to create two series objects Obj1 and Obj2 (data given below) and
display the following attributes in the format given below.
Structure of Series objects Output format
Obj1 Obj2
A 6700 A 640
B 5600 B 720
C 5000 C 1020
D 5200 D 437
E nil
#CODE
import pandas as pd
import numpy as np
Obj1 = pd.Series([6700,5600,5000,5200,np.NaN], index=['A', 'B', 'C', 'D', 'E'])
Obj2 = pd.Series([640,720,1020,437], index=['A', 'B', 'C', 'D'])
print("Attribute Name\t\tObject 1\t\tObject 2")
print("_______________________________________________________")
print("Data Type\t\t", Obj1.dtype, "\t\t", Obj2.dtype)
print("Shape \t\t", Obj1.shape, "\t\t\t", Obj2.shape)
print("No. of Bytes\t\t", Obj1.nbytes, "\t\t\t", Obj2.nbytes)
print("No. of Dimensions\t",Obj1.ndim,"\t\t\t",Obj2.ndim)
print("Item Size \t",Obj1.size,"\t\t\t",Obj2.size)
print("Has Nans? \t\t",Obj1.hasnans,"\t\t\t",Obj2.hasnans)
print("Empty \t",Obj1.empty,"\t\t\t",Obj2.empty)
SAMPLE OUTPUT
Attribute Name Object 1 Object 2
__________________________________________________________________________
Data Type float64 int64
Shape (5,) (4,)
9
No. of Bytes 40 32
No. of Dimensions 1 1
Item Size 5 4
Has Nans? True False
Empty False False
LAB ACTIVITY 5 Date:05-05-22
AIM: Write a program in python to create a dataframe fruits from following data and answer the
questions (i) to (v)-
Color Count Price
Orange Yellow 30 40
Orange Green 19 30
Mango Yellow 25 60
Mango Green 29 120
Pear Green 65 150
(i) Add a new column ‘Variety’ contains data as ‘Normal’, ‘Normal’, ‘Dashari’, ‘Hafooj’, ‘Normal’
(ii) Add a new row ‘Apple’ containing Red, 40,190, Kashmiri.
(iii) Display price of all fruits.
(iv) Display color and price of all fruits.
(v) Display all columns from count to variety.
#CODE
import pandas as pd
d=
{'Color':['Yellow','Green','Yellow','Green','Green'],'Count':[30,19,25,29,65],'Price':[40,30,60,120,150
]}
fruits=pd.DataFrame(d,index=['Orange','Orange','Mango','Mango','Pear'])
print("Original Dataframe\n===================\n",fruits)
Output (i)
============================================
Color Count Price Variety
Orange Yellow 30 40 Normal
Orange Green 19 30 Normal
Mango Yellow 25 60 Dashari
Mango Green 29 120 Hafooj
Pear Green 65 150 Normal
Output (ii)
============================================
Color Count Price Variety
Orange Yellow 30 40 Normal
Orange Green 19 30 Normal
Mango Yellow 25 60 Dashari
Mango Green 29 120 Hafooj
Pear Green 65 150 Normal
Apple Red 40 190 Kashmiri
Output (iii)
===================
Orange 40
Orange 30
Mango 60
Mango 120
Pear 150
Apple 190
Name: Price, dtype: int64
11
Output (iv)
=============================
Color Price
Orange Yellow 40
Orange Green 30
Mango Yellow 60
Mango Green 120
Pear Green 150
Apple Red 190
Output (v)
==============================
Count Price Variety
Orange 30 40 Normal
Orange 19 30 Normal
Mango 25 60 Dashari
Mango 29 120 Hafooj
Pear 65 150 Normal
Apple 40 190 Kashmiri
12
LAB ACTIVITY 6 Date: 11-05-22
AIM Write a program in python to perform following arithmetic operations on dataframe. df1 df2
df1 df2
0 1 2 0 1 2
0 3 4 5.0 0 2.0 8.0 3
1 2 7 NaN 1 NaN 5.0 5
2 3 2 1.0 2 NaN NaN 2
#CODE
import pandas as pd
import numpy as np
#Creation of dataframe df1
df1 = pd.DataFrame([[3,4,5],[2,7,np.NaN],[3,2,1]])
#Scaler arithmetic’s
df7=df1 + 10
13
print("Output (v)\n===================\n df1 + 10\n",df7)
SAMPLE OUTPUT
Output (ii)
===================
df1+df2
0 1 2
0 5.0 12.0 8.0
1 NaN 12.0 NaN
2 NaN NaN 3.0
Output (ii)
===================
df1 - df2
0 1 2
0 1.0 -4.0 2.0
1 NaN 2.0 NaN
2 NaN NaN -1.0
Output (iii)
===================
df1 X df2
0 1 2
0 6.0 32.0 15.0
1 NaN 35.0 NaN
2 NaN NaN 2.0
Output (iv)
===================
df1/df2
0 1 2
0 1.5 0.5 1.666667
1 NaN 1.4 NaN
2 NaN NaN 0.500000
Output (v)
===================
df1 + 10
0 1 2
0 13 14 15.0
1 12 17 NaN
2 13 12 11.0
14
LAB ACTIVITY 7 Date: 11-05-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df
#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) Display number of masks bought by SMS.
print("\nMasks bought by SMS = ",Covid_df.Masks['SMS'])
SAMPLE OUTPUT
Masks bought by SMS = 30000
15
SMS 2700000
AIIMS 4200000
SDMH 20000
FORTIS 150000
SDMH 2500000
Name: Amount, dtype: int64
Amount paid by SMS and AIIMS
Amount
AIIMS 4200000
SMS 2700000
Fortis Hospital =
Masks 15000
Gloves 5000
Amount 150000
Name: FORTIS, dtype: int64
16
LAB ACTIVITY 8 Date: 12-07-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df
#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(ii) Find all rows with label ‘SDMH’ with all columns.
print("\n",Covid_df.loc['SDMH',:]) # Covid_df.loc['SDMH']
#(iv) List single True or False to signify if all amount more than 200000 or not.
print("\nChecking if all row contains amount greater than 200000 =
",(Covid_df['Amount']>200000).all())
SAMPLE OUTPUT
17
Gloves
AIIMS 1500000
18
LAB ACTIVITY 9 Date: 27-07-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df
#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) List only the columns Masks and Amount.
print("\n",Covid_df[['Masks','Amount']])
#(v) Display details of Masks and Gloves bought by AIIMS and SDMH
print("\n",Covid_df.loc[['AIIMS','SDMH'],['Masks','Gloves']])
19
SAMPLE OUTPUT
Masks Amount
SMS 30000 2700000
AIIMS 50000 4200000
SDMH 10000 20000
FORTIS 15000 150000
SDMH 35000 2500000
Masks Gloves
SMS 30000 80000
AIIMS 50000 1500000
SDMH 10000 500000
FORTIS 15000 5000
SDMH 35000 30000
Masks Gloves
AIIMS 50000 1500000
SDMH 10000 500000
SDMH 35000 30000
20
LAB ACTIVITY 10 Date: 03-08-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df
#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) Add new row as SHALBY 5000 20000 150000
Covid_df.loc['SHALBY'] = [5000,20000,150000]
print("Output of (i)\n",Covid_df)
21
SAMPLE OUTPUT
Output of (i)
Masks Gloves Amount
SMS 30000 80000 2700000
AIIMS 50000 1500000 4200000
SDMH 10000 500000 20000
FORTIS 15000 5000 150000
SDMH 35000 30000 2500000
SHALBY 5000 20000 150000
Output of (ii)
Masks Gloves Amount Remarks
SMS 30000 80000 2700000 Paid
AIIMS 50000 1500000 4200000 Pending
SDMH 10000 500000 20000 Paid
FORTIS 15000 5000 150000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid
Output of (iii)
Masks Gloves Amount Remarks
AIIMS 50000 1500000 4200000 Pending
SDMH 10000 500000 20000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid
Output of (iv)
Masks Gloves Amount Remarks
AIIMS 50000 1500000 4200000 Paid
SDMH 10000 500000 20000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid
Output of (v)
Masks Gloves
AIIMS 50000 1500000
SDMH 10000 500000
SDMH 35000 30000
SHALBY 5000 20000
22
LAB ACTIVITY 11 Date: 10-08-22
AIM Write a Program to read CSV file and show its data in python using dataFrames and pandas.
#CODE
import pandas as pd
df=pd.read_csv("d://students.csv", nrows=3)
print("To display selected number of rows from beginning")
print(df)
SAMPLE OUTPUT
To display selected number of rows from beginning
Name Marks Class Section
0 Megha 65 12 C
1 Rachit 73 11 B
2 Neeraj 45 11 C
23
LAB ACTIVITY 12 Date: 16-08-22
AIM Write a Program to export the contents of following dataframe to a CSV file with a separator
character @.
#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
shop_df.to_csv("d:\\shop.csv",sep='@')
SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN
Contents of shop.csv
@Name@Product@Target@Sales
A@East@Oven@56000.0@58000.0
B@West@AC@70000.0@68000.0
C@Central@AC@75000.0@78000.0
D@South@Oven@60000.0@61000.0
E@North@TV@@
F@Rural@Music Player@@
24
LAB ACTIVITY 13 Date: 19-08-22
AIM Write a Program to export the contents of following dataframe to a CSV file with a separator
character @ along with the NaN values stored as Unplanned and separator as $.
#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
shop_df.to_csv("d:\\shop.csv",sep='$',na_rep=’Unplanned’)
SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN
Contents of shop.csv
$Name$Product$Target$Sales
A$East$Oven$56000.0$58000.0
B$West$AC$70000.0$68000.0
C$Central$AC$75000.0$78000.0
D$South$Oven$60000.0$61000.0
E$North$TV$Unplanned$Unplanned
F$Rural$Music Player$Unplanned$Unplanned
25
LAB ACTIVITY 14 Date: 27-08-22
AIM Write a Program to extract the contents of following dataframe row wise
#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
for (row, rowSeries) in shop_df.iterrows():
print(“Row index:”,row)
print(“Containing:”)
print(rowSeries)
SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN
Row index: A
Containing:
===================
Name East
Product Oven
Target 56000
Sales 58000
Name: A, dtype: object
Row index: B
Containing:
===================
Name West
Product AC
Target 70000
26
Sales 68000
Name: B, dtype: object
Row index: C
Containing:
===================
Name Central
Product AC
Target 75000
Sales 78000
Name: C, dtype: object
Row index: D
Containing:
===================
Name South
Product Oven
Target 60000
Sales 61000
Name: D, dtype: object
Row index: E
Containing:
===================
Name North
Product TV
Target NaN
Sales NaN
Name: E, dtype: object
Row index: F
Containing:
===================
Name Rural
Product Music Player
Target NaN
Sales NaN
Name: F, dtype: object
27
LAB ACTIVITY 15 Date: 30-08-22
AIM Write a Program to extract the contents of following dataframe column wise
#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN
29
LAB ACTIVITY 16 Date: 30-08-22
AIM Write a Program to store records of students of a class using Boolean indexing where index
of Girl student records is True and that of Boy records is False. Subsequently extract rows
containing Girls & Boys.
#CODE
import pandas as pd
stu_marks=[[1,'AHAM KUMAR KHARA',42],\
[5,'DARSHANA SHAH',47],\
[8,'SAMIR PRUSTY',44],\
[11,'ABHIJIT DEY',42],\
[12,'SALONI SINGH',47],\
[19,'PRIYANKA ROY',42],\
[28,'KRISTINA WILLIAMS',49]]
marks_df=pd.DataFrame(stu_marks,columns=['ROLL
NO','NAME','IP'],index=[False,True,False,False,True,True,True])
print("\nMarks of Students in IP\n============================================")
print(marks_df)
print("\nMarks of Girls in IP\n============================================")
print(marks_df.loc[True])
print("\nMarks of Boys in IP\n=============================================")
print(marks_df.loc[False])
SAMPLE OUTPUT
Marks of Students in IP
==================================================
ROLL NO NAME IP
False 1 AHAM KUMAR KHARA 42
True 5 DARSHANA SHAH 47
False 8 SAMIR PRUSTY 44
False 11 ABHIJIT DEY 42
True 12 SALONI SINGH 47
True 19 PRIYANKA ROY 42
True 28 KRISTINA WILLIAMS 49
Marks of Girls in IP
==================================================
ROLL NO NAME IP
True 5 DARSHANA SHAH 47
True 12 SALONI SINGH 47
True 19 PRIYANKA ROY 42
True 28 KRISTINA WILLIAMS 49
30
Marks of Boys in IP
==================================================
ROLL NO NAME IP
False 1 AHAM KUMAR KHARA 42
False 8 SAMIR PRUSTY 44
False 11 ABHIJIT DEY 42
31
LAB ACTIVITY 17 Date: 14-09-22
Write code to
(a) Display dashed line
(b) Display + (plus) marker
(c )Change the marker color to blue
#CODE
import matplotlib.pyplot as plt
cls=['I','II','III','IV','V']
students=[43,37,39,33,34]
plt.plot(cls,students,color='r',linestyle='dashed',marker='+',markeredgecolor='b')
plt.xlabel("CLASS")
plt.ylim(30,45)
plt.ylabel("No of Students")
plt.title("Enrollment of a School")
plt.show()plt.show()
SAMPLE OUTPUT
32
LAB ACTIVITY 18 Date: 27-09-22
AIM Write a program in python to plot a line graph of marks obtained in five subjects by five
students st
#CODE
import matplotlib.pyplot as plt
student=['Amit',"Bhavesh",'Chetan','Dhirubhai','Ehsan']
std1=[12,66,32,42,33]
std2=[32,55,64,76,98]
std3=[34,9,76,86,33]
std4=[34,66,23,43,17]
std5=[45,75,22,45,73]
plt.plot(student,std1,marker='s',markersize='5',label='Chemistry')
plt.plot(student,std2,marker='s',markersize='5',label='Computer Science')
plt.plot(student,std3,marker='s',markersize='5',label='English')
plt.plot(student,std4,marker='s',markersize='5',label='Maths')
plt.plot(student,std5,marker='s',markersize='5',label=' Physics ')
plt.xlabel('Student Name')
plt.ylabel('Marks of various Subjects')
plt.legend(loc='upper left')
plt.show()
SAMPLE OUTPUT
33
LAB ACTIVITY 19 Date: 29-09-22
AIM: Write a program to plot a bar chart in python to display the result of a school for five
consecutive years.
(a) Change the colour bars in sequence as red, yellow, green, blue, cyan
(b) Change width of bars in sequence as 0.5,0.6,0.7,0.8,0.9
#CODE
SAMPLE OUTPUT
34
LAB ACTIVITY 20 Date: 14-10-22
AIM Write a program to create the histogram for the data is given below.
Weight measurements for 16 small orders of French Fries (in grams).
78, 72, 69, 81, 63, 67, 65, 73, 79, 74, 71, 83, 71, 79, 80, 69
(a) Create a simple histogram from above data.
(b) Create a horizontal histogram from above data.
(c) Create a step type of histogram from above data.
(d) Create a cumulative histogram from above data.
#CODE
import numpy as np
import matplotlib.pyplot as plt
wff=np.array([78,72,69,81,63,67,65,75,79,74,71,83,71,79,80,69]) #weight of French fries
"""(a) Create a simple histogram from above data."""
plt.hist(wff)
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Normal Histogram")
plt.show()
35
"""(b) Create a horizontal histogram from above data."""
plt.hist(wff, orientation='horizontal')
plt.xlabel("Frequency")
plt.ylabel("Weight of French fries")
plt.title("Horizontal Histogram")
plt.show()
"""(c) Create a step type of histogram from above data."""
plt.hist(wff,histtype='step')
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Step Type Histogram")
plt.show()
"""(d) Create a cumulative histogram from above data."""
plt.hist(wff,cumulative=True)
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Cumulative Histogram")
plt.show()
36
SAMPLE OUTPUT (b)
37
SAMPLE OUTPUT (d)
38
AIM Write various MySQL queries.
• Create a database kvc.
• Inside the database create table emp.
• Insert the data as per shown in the screenshot.
39
Ans. SELECT distinct(job) FROM emp;
3. Write a query to display the empname who is earning more than 2500.
Ans. SELECT ename FROM emp WHERE sal>2500;
4. Write a query to display the managers working in department number 10. Ans.
Ans. SELECT ename , job, deptno FROM emp WHERE JOB=’MANAGER’ and deptno=10;
BLAKE
6. Write a query to display the managers who earn more than 2800.
40
Ans. SELECT ename, job, sal FROM emp WHERE job='MANAGER' AND sal>2800;
7. Write a query to display the department number where more than three employees are
working.
Ans. SELECT deptno, count(*) as ‘No of Employees’ FROM emp GROUP BY deptno HAVING
count(*)>3;
8. Write a query to display the name of employee with their salary in order of their joining.
Ans. SELECT ename, sal, hiredate FROM emp ORDER BY hiredate;
9. Write a query to display the name and salary from department number 30 and sorted in
descending order of salary.
Ans. SELECT ename, deptno, sal FROM emp WHERE deptno=30 ORDER BY sal DESC;
11. Write a SQL command to increase the salary by 300 to the employees belong to deptno 20.
Ans. UPDATE emp SET sal=sal+300 WHERE deptno=20;
13. Write a query to display the employee name earning between 1500 and 2500.
42
Ans.
Method-1 SELECT ename, sal FROM emp WHERE sal>=1500 AND sal<=2500;
Method-2 SELECT ename, sal FROM emp WHERE sal BETWEEN (1500 and 2500);
14. Write a query to display the employee name joined in the year 1981.
Ans.
Method-1 SELECT ename, hiredate FROM emp WHERE hiredate>='1981-01-01' AND
hiredate<='1981-12-31';
Method-2 SELECT ename, hiredate FROM emp WHERE hiredate between ("'1981-01-01"
and "'1981-12-31");
Method-3 SELECT ename, hiredate FROM emp WHERE year(hiredate)=1981;
16. Write a query to see average salary paid to department number 20.
Ans. SELECT deptno, AVG(sal) FROM emp WHERE deptno=20;
43