Professional Documents
Culture Documents
INFORMATICS PRACTICES
1
DELHI PUBLIC SCHOOL
NERUL, NAVI MUMBAI
Certificate
Roll Number.
practical examination.
2
INDEX
5. ATTRIBUTES OF SERIES
04-04-23 14-15
7.
ARITHMETIC OPERATIONS ON SERIES 04-04-23 18-19
8.
VECTOR OPERATIONS ON SERIES 04-04-23 20-21
9.
CREATING SERIES DATA NDARRAY 04-04-23 22-23
10.
CREATION OF DATAFRAME USING DIFFERENT 16-04-23 24-26
3
TYPES
14.
IMPORT CSV FILE TO DATAFRAME 16-04-23 37-38
15.
EXPORT DATAFRAME TO CSV FILE 16-04-23 39-40
16.
PLOT SINGLE LINE CHART 06-05-23 41-43
18.
PLOT MULTIPLE LINE CHART 06-05-23 46-47
19.
MULTI BAR CHART 06-05-23 48-50
4
20.
LINE PLOT 06-05-23 51-52
24.
SQL SINGLE ROW FUNCTIONS 13-07-23 61-64
25.
SQL SINGLE ROW FUNCTIONS 14-07-23 65-68
5
1. CREATE A SERIES EMPLOYEE WITH EMPLOYEE NAME AND
MONTHLY SALARY WHERE ENAME(INDEX) AND SALARY(VALUE)
Ram 10000
Anil 30000
Ganesh 15000.5
Biju 10000
Niketan 30000
a. USING LIST
b. USING DICTIONARY
CODE:
import pandas as pd
#using list
ename=['Ram','Anil','Ganesh','Biju','Niketan']
salary=[10000,30000,15000.5,10000,30000]
employee=pd.Series(salary,ename)
print(employee)
#using dictionary
e={'Ram':10000,'Anil':30000,'Ganesh':15000.5,'Biju':10000,'Niketan':300
00}
employee=pd.Series(e)
6
print(employee)
OUTPUT:
Ram 10000.0
Anil 30000.0
Ganesh 15000.5
Biju 10000.0
Niketan 30000.0
dtype: float64
7
2. CREATE A SERIES DATA WITH ODD NUMBERS BETWEEN 50 TO 100.
CODE:
import pandas as pd
data=pd.Series(range(51,100,2))
print(data)
8
OUTPUT:
0 51
1 53
2 55
3 57
4 59
5 61
6 63
7 65
8 67
9 69
10 71
11 73
12 75
13 77
14 79
15 81
16 83
17 85
18 87
19 89
20 91
21 93
22 95
9
23 97
24 99
dtype: int64
101 7
111 7
121 7
CODE:
import pandas as pd
p=pd.Series(7,[101,111,121])
print(p)
10
OUTPUT:
101 7
111 7
121 7
dtype: int64
11
4. WRITE A PROGRAM TO CREATE A SERIES FROM A GIVEN TUPLE
DATA:
data=(‘1’,’Aman’,86.3,’A’).
CODE:
import pandas as pd
data=('1','Aman',86.3,'A')
a=pd.Series(data)
print(a)
12
OUTPUT:
0 1
1 Aman
2 86.3
3 A
dtype: object
13
5. DO THE FOLLOWING FOR THE ALREADY CREATED SERIES
EMPLOYEE:
1. DISPLAY THE INDEX.
2. DISPLAY THE NUMBER OF ROWS AND COLUMNS .
3. DISPLAY THE DATATYPE.
4. DISPLAY THE TOTAL NUMBER OF EMPLOYEES.
5. ASSIGN THE NAME TO THE INDEX AS ‘ENAME’.
6. ASSIGN THE NAME OF THE SERIES AS EMPLOYEE.
7. DISPLAY THE DIMENSIONS OF THE SERIES.
8. DISPLAY THE DATATYPE OF THE SERIES.
9. CHECK THE SERIES FOR MISSING DATA.
10. CHECK IF SERIES IS EMPTY OR NOT?
14
CODE:
import pandas as pd
import numpy as np
name=['Ram','Anil','Ganesh','Biju','Niketan']
salary=[10000,30000,15000.5,10000,30000]
emp=pd.Series(salary,name)
print(emp)
print(emp.index)
print(emp.size)
print(emp.dtype)
print(emp.size)
emp.index.nam='Ename'
print(emp.index.nam)
emp.nam='Employee'
print(emp.nam)
print(emp.ndim)
print(emp.hasnans)
print(emp.empty)
OUTPUT:
Ram 10000.0
Anil 30000.0
Ganesh 15000.5
Biju 10000.0
Niketan 30000.0
dtype: float64
Index(['Ram', 'Anil', 'Ganesh', 'Biju', 'Niketan'], dtype='object')
5
15
float64
5
Ename
Employee
1
False
False
CODE:
import pandas as pd
ename=['Ram','Anil','Ganesh','Biju','Niketan']
salary=[10000,30000,15000.5,10000,30000]
employee=pd.Series(salary,ename)
print(employee.index)
print(employee.values)
print(employee['Niketan'])
print(employee['Biju':'Ganesh':-1])
employee['Anil']=20000
print(employee.head(3))
print(employee.tail(6))
employee=employee.drop('Ram')
print(employee[: :-1])
b=employee['Biju']
employee['Biju']=b+(b*10/100)
print(employee.values)
employee['Anil':'Niketan']=employee['Anil':'Niketan']*2
print(employee[employee>15000])
print(employee.sort_values(ascending=False))
print(employee.sort_index(ascending=True))
OUTPUT:
Class11
18
Science 198
Commer 100
ce
Humanit 150
ies
Class12
Science 108
Commer 86
ce
Humanit 55
ies
CODE:
import pandas as pd
c11={'Science':198,'Commerce':100,'Humanities':50}
c12={'Science':108,'Commerce':86,'Humanities':55}
Class11=pd.Series(c11)
Class12=pd.Series(c12)
print(Class11)
print(Class12)
print(Class11+Class12)
OUTPUT:
19
Science 198
Commerce 100
Humanities 50
dtype: int64
Science 108
Commerce 86
Humanities 55
dtype: int64
Science 306
Commerce 186
Humanities 105
dtype: int64
20
8.GIVEN THE FOLLOWING SERIES S1 AND S2:
s1
A 23
B 50
C 34
D 70
s2
a 8
B NaN
C 7
e 9
CODE:
import pandas as pd
import numpy as np
s1=pd.Series([23,50,34,70],['A','B','C','D'])
s2=pd.Series([8,np.NaN,7,9],['a','B','C','E'])
print(s1)
print(s2)
print(s1*s2)
print(s1+s2)
print(s1-s2)
print(s1/s2)
21
OUTPUT:
A 23
B 50
C 34
D 70
dtype: int64
a 8.0
B NaN
C 7.0
E 9.0
dtype: float64
A NaN
B NaN
C 238.0
D NaN
E NaN
a NaN
dtype: float64
A NaN
B NaN
C 41.0
D NaN
E NaN
a NaN
dtype: float64
A NaN
B NaN
C 27.0
D NaN
E NaN
a NaN
dtype: float64
A NaN
B NaN
C 4.857143
D NaN
E NaN
a NaN
dtype: float64
22
9.CREATE A SERIES DATA USING NDARRAY THAT HAS 10 ELEMENTS IN
THE RANGE 10 TO 100.
CODE:
import pandas as pd
import numpy as np
a=np.arange(10,110,10)
data=pd.Series(a)
print(data)
23
OUTPUT:
0 10
1 20
2 30
3 40
4 50
5 60
6 70
7 80
8 90
9 100
dtype: int32
24
10.CREATE AND DISPLAY THE FOLLOWING DATAFRAME EMPLOYEE
USING:
A. LIST
B. DICTIONARY
C. DICTIONARY OF SERIES
D. 2D DICTIONARY
CODE:
import pandas as pd
#using list
a=[[1001,'Ram', 10000,'10-10-2000'],[1002,'Anil',30000,'03-20-2001'],
[1003,'Ganesh',15000.5,'12-05-2002'],[1004,'Biju',10000,'09-10-2000'],
[1005,'Niketan',30000,'09-10-2000'],[1006,'Praful',15000.5,'10-10-2000'],
[1007,'Santosh',10000,'03-20-2001'],[1008,'Anant',30000,'12-05-2002'],
[1009,'Laxmi',15000.5,'09-10-2000'],[1010,'Gaurav',20000,'08-08-1998']]
employee=pd.DataFrame(a,columns=['eno','ename','salary','doj']
)
print(employee)
#using 2D dictionary
eno=[1001,1002,1003,1004,1005,1006,1007,1008,1009,1010]
ename=['Ram','Anil','Ganesh','Biju','Niketan','Praful','Santosh','An
ant','Laxmi','Gaurav']
salary=[10000,30000,15000.5,10000,30000,15000.5,10000,30000,15000.5,2
0000]
doj=['10-10-2000','03-20-2001','12-05-2002','09-10-2000','08-08-1998','10-10-
2000','03-20-2001','12-05-2002','09-10-2000','08-08-1998']
a={'eno':eno,'ename':ename,'salary':salary,'doj':doj}
employee=pd.DataFrame(a)
25
print(employee)
#using dictionary
data={'eno':{'01':1001,'02':1002,'03':1003,'04':1004,'05':1005,'06':1006,'07':100
7,
'08':1008,'09':1009,'010':1010},
'ename':{'01':'Ram','02':'Anil','03':'Ganesh','04':'Biju','05':'Niketan','06':'P
raful',
'07':'Santosh','08':'Anant','09':'Laxmi','010':'Gaurav'}, 'salary'
:{'01':10000,'02':30000,'03':15000.5,'04':10000,'05':30000,'06':15000.5,
'07':10000,'08':30000,'09':15000.5,'010':20000},
'doj':{'01':'10-10-2000','02':'03-20-2001','03':'12-05-2002','04':'09-10-2000',
'05':'08-08-1998','06':'10-10-2000','07':'03-20-2001','08':'12-05-2002',
'09':'09-10-2000','010':'08-08-1998'}}
employee=pd.DataFrame(data)
print(employee)
26
OUTPUT:
27
11.CONSIDER THE DATAFRAME EMPLOYEE CREATED IN QUESTION
NUMBER 10 AND DO THE FOLLOWING:
A. THE ROW LABELS OF THE DATAFRAME.
B. THE COLUMN LABELS OF THE DATAFRAME.
C. THE AXES OF THE DATAFRAME.
D. THE DATATYPES OF THE DATAFRAME.
E. THE NUMBER OF ROWS AND COLUMNS OF THE
DATAFRAME.
F. TRANSPOSE THE DATAFRAME.
G. THE NUMPY REPRESENTATION OF THE DATAFRAME.
H. CHECK AND DISPLAY WHETHER THE DATAFRAME IS
EMPTY OR NOT.
CODE:
import pandas as pd
eno=[1001,1002,1003,1004,1005,1006,1007,1008,1009,1010]
ename=['Ram','Anil','Ganesh','Biju','Niketan','Praful','Santosh','An
ant','Laxmi','Gaurav']
salary=[10000,30000,15000.5,10000,30000,15000.5,10000,30000,15000.5,2
0000]
doj=['10-10-2000','03-20-2001','12-05-2002','09-10-2000','08-08-1998','10-10-
2000',
'03-20-2001','12-05-2002','09-10-2000','08-08-1998']
a={'eno':eno,'ename':ename,'salary':salary,'doj':doj}
employee=pd.DataFrame(a)
print(employee.index)
print(employee.columns)
print(employee.axes)
print(employee.dtypes)
print(employee.shape)
print(employee.T)
print(employee.values)
print(employee.empty)
28
OUTPUT:
[4 rows x 10 columns]
[[1001 'Ram' 10000.0 '10-10-2000']
[1002 'Anil' 30000.0 '03-20-2001']
[1003 'Ganesh' 15000.5 '12-05-2002']
[1004 'Biju' 10000.0 '09-10-2000']
[1005 'Niketan' 30000.0 '08-08-1998']
[1006 'Praful' 15000.5 '10-10-2000']
[1007 'Santosh' 10000.0 '03-20-2001']
[1008 'Anant' 30000.0 '12-05-2002']
[1009 'Laxmi' 15000.5 '09-10-2000']
29
[1010 'Gaurav' 20000.0 '08-08-1998']]
False
CODE:
import pandas as pd
eno=[1001,1002,1003,1004,1005,1006,1007,1008,1009,1010]
ename=['Ram','Anil','Ganesh','Biju','Niketan','Praful','Santosh','An
ant','Laxmi','Gaurav']
salary=[10000,30000,15000.5,10000,30000,15000.5,10000,30000,15000.5,2
0000]
doj=['10-10-2000','03-20-2001','12-05-2002','09-10-2000','08-08-1998','10-10-
2000','03-20-2001','12-05-2002','09-10-2000','08-08-1998']
a={'eno':eno,'ename':ename,'salary':salary,'doj':doj}
employee=pd.DataFrame(a)
employee.set_index('ename',inplace=True)
print(employee)
print(employee.head(4))
30
print(employee.tail(5))
print(employee[0:10:2])
print(employee[::-1])
print(employee['eno'])
print(employee[['eno','salary']])
print(employee.iloc[8,])
print(employee.iloc[1:5,])
print(employee.loc['Ram':'Gaurav','eno':'doj'])
print(employee.loc[['Ram','Niketan','Gaurav'],['eno','doj']])
print(employee.iloc[2:5,])
print(employee.at['Niketan','salary'])
31
OUTPUT:
34
13.CREATE THE FOLLOWING DATAFRAME UT:
OBSERVE THE DATAFRAME UT AND WRITE THE COMMANDS TO DO
THE FOLLOWING:
A. ADD A NEW COLUMN COMP WITH 25 MARKS IN EACH.
B. ADD A NEW COLUMN TOTAL WHICH WILL DISPLAY THE TOTAL
OF ALL SUBJECTS [MATHS+SCIENCE+HINDI+ENG+COMP].
C. ADD A NEW ROW TO A DATAFRAME UT [ YOUR NAME UT1 AND
MARKS RESPECTIVELY].
D. ADD ONE MORE STUDENT [SHIVI WITH 0 MARKS UT1 IN ALL
SUBJECTS].
E. DELETE THE RECORD OF RAMAN.
F. DELETE THE COLUMN TOTAL.
G. RENAME INDEX AS S1, S2, S3.
H. DISPLAY MISHTI’S RECORDS.
I. DISPLAY MISHTI’S RECORDS WITH MATHS AND SCIENCE MARKS.
CODE:
import pandas as pd
name=['Raman','Raman','Raman','Zuhaire','Zuhaire','Zuhaire','As
hravy','Ashravy','Ashravy',
'Mishti','Mishti','Mishti']
ut=[1,2,3,1,2,3,1,2,3,1,2,3]
35
maths=[22,21,14,20,23,22,23,24,12,15,18,17]
science=[21,20,19,17,15,18,19,22,25,22,21,18]
sst=[18,17,15,22,21,19,20,24,19,25,25,20]
hindi=[20,22,24,24,25,23,15,17,21,22,24,25]
eng=[21,24,23,19,15,13,22,21,23,22,23,20]
m={'Name':name,'UT':ut,'Maths':maths,'Science':science,'S.st':sst,'Hi
ndi':hindi,'Eng':eng}
UT=pd.DataFrame(m)
comp=[25,25,25,25,25,25,25,25,25,25,25,25]
UT['Comp']=comp
total=[]
for i in range(0,12):
total.append(maths[i]+science[i]+sst[i]+hindi[i]+eng[i]+comp[i])
UT['Total']=total
print(UT)
UT.loc[12,:]=['Ananya',1,23,21,22,20,23,25,134]
UT.loc[13,:]=['Shivi',1,0,0,0,0,0,0,0]
UT.drop(UT.index[UT['Name']=='Raman'],axis=0,inplace=True)
del UT['Total']
UT.index=['s1','s2','s3','s4','s5','s6','s7','s8','s9','s10','s11']
print(UT)
print(UT.loc['s7':'s9',])
print(UT.loc['s7':'s9',['Name','UT','Maths','Science']])
36
OUTPUT:
38
WRITE THE PYTHON CODE TO CONVERT EMPLOYEE.CSV TO
DATAFRAME EMP.
A. DISPLAY ENTIRE DATAFRAME.
B. WRITE THE PYTHON CODE TO CONVERT EMPLOYEE.CSV TO
DATAFRAME EMP1 WITH FIRST FIVE ROWS AND DIFFERENT
HEADER (DONT USE THE HEADER OF CSV FILE). DISPLAY THE
DATAFRAME.
C. WRITE THE PYTHON CODE TO READ THE ALTERNATE ROWS OF
CSV FILE EMPLOYEE INTO DATAFRAME EMP2.
CODE:
import pandas as pd
import numpy as np
emp=pd.read_csv('employee.csv')
print(emp)
emp1=pd.read_csv('employee.csv',names=['rno','name','sal','dptno'
,'comm'])
print(emp1.head(5))
emp2=pd.read_csv('employee.csv')
print(emp2[0:10:2])
OUTPUT:
40
CODE:
import pandas as pd
import numpy as np
deptno=[10,20,30,40,50]
dname=['fin','sales','res’,np.NaN,'mkt']
loc=['Delhi','Navi Mumbai','Jaipur','Mumbai','Delhi']
dpt={'deptno':deptno,'dname':dname,'loc':loc}
department=pd.DataFrame(dpt)
department['dname']=department['dname'].replace(np.NaN,'Nu
ll')
print(department)
department.to_csv('dep.csv',sep='\t')
d=pd.read_csv('dep.csv')
print(d)
OUTPUT:
42
DEPICT THE SALES FOR THE THREE WEEKS USING A LINE CHART.
IT SHOULD HAVE THE FOLLOWING:
I. CHART TITLE AS “MELA SALES REPORT”.
II. X AXIS LABEL AS DAYS.
II. Y AXIS LABEL AS “SALES IN RS”.
IV. LINE COLOURS ARE RED FOR WEEK 1, BLUE FOR WEEK 2 AND
BROWN FOR WEEK 3
V. CUSTOMIZE IT BY MARKER="*", MARKERIZE=10, LINEWIDTH=3,
LINESTYLE="--”.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv('melasales.csv')
n=['mon','tue','wed','thu','fri','sat','sun']
d=pd.DataFrame(data)
w1=d['week1']
w2=d['week2']
w3=d['week3']
plt.plot(n,w1,marker='*',markersize=10,linewidth=3,linestyle='--
',color='red',label='week1')
plt.plot(n,w2,marker='*',markersize=10,linewidth=3,linestyle='-
-',color='blue',label='week2')
plt.plot(n,w3,marker='*',markersize=10,linewidth=3,linestyle='-
-',color='brown',label='week3')
plt.legend()
plt.title('Mela Sales Report')
43
plt.xlabel('Days')
plt.ylabel('Sales in Rs')
plt.show()
44
OUTPUT:
45
17.THE FOLLOWING DATA REPRESENTS NUMBER OF PEOPLE EMPLOYED
IN 2019 AND 2020.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','
Dec']
a=[153454,153704,153964,154528,154216,153653,153748,154073,153918,153709,
154041,153613]
b=[153250,153302,153392,153420,153700,153409,153358,153674,154004,154057,
153937,153887]
d=pd.DataFrame({'2019':a,'2020':b},index=month)
print(d)
plt.plot(month,d['2019'], marker='h', markersize=8,
linewidth=4,
linestyle='-.', markeredgecolor='blue', label=2019)
plt.plot(month, d['2020'], marker='h', markersize=8,l
inewidth=4,l
inestyle='-.', markeredgecolor='blue', label=2020)
plt.legend()
plt.xlabel('Month')
plt.ylabel('Number of people')
plt.title('People employed 2019 and 2020')
plt.show()
46
OUTPUT:
47
18.CREATE A MULTILINE CHART ABOUT EMPLOYEE REGISTRATION
ACCORDING TO PERSONAL VALUES WITH THE FOLLOWING FEATURES:
D. INCREASE THE LINE WIDTH AND GIVE THE LEGEND AS 2010 AND
2011.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','No
v','Dec']
a=[43,61,44,78,82,67,65,63,54,39,47,55]
b=[47,59,53,84,79,77,72,64,60,48,45,54]
plt.plot(month, a, marker='X', markersize=7, linewidth=3,
linestyle='solid', markeredgecolor='black', label=2010)
plt.plot(month, b, marker='X', markersize=7, linewidth=3,
linestyle='solid', markeredgecolor='black', label=2011)
plt.legend()
plt.xlabel('Month')
plt.ylabel('Number of people')
plt.title('People employed 2010 and 2011')
plt.show()
plt.savefig('employment.pdf')
48
OUTPUT:
49
19.PLOT A MULTI BAR CHART USING THE FOLLOWING DATA FOR
MUMBAI CITY FROM THE INDIAN METEREOLOGICAL DEPARTMENT.
month avg high temp avg low temp avg rainfall rel
humidity
0 Jan 31.1 17.3 0.3 69
1 Feb 31.3 18.2 0.4 67
2 Mar 32.8 21.4 0.0 69
3 Apr 33.2 24.2 0.1 71
4 May 33.6 27.0 11.3 70
5 Jun 32.4 26.6 493.1 80
6 Jul 30.4 25.5 840.7 86
7 Aug 30.0 25.1 585.2 86
8 Sep 30.7 24.8 341.4 83
9 Oct 33.4 23.8 89.3 78
10 Nov 33.7 21.3 9.9 71
11 Dec 32.4 18.5 1.6 69
CODE:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
month=['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','No
v','Dec']
high=[31.1,31.3,32.8,33.2,33.6,32.4,30.4,30.0,30.7,33.4,33.7,32.4]
low=[17.3,18.2,21.4,24.2,27.0,26.6,25.5,25.1,24.8,23.8,21.3,18.5]
rain=[0.3,0.4,0.0,0.1,11.3,493.1,840.7,585.2,341.4,89.3,9.9,1.6]
hum=[69,67,69,71,70,80,86,86,83,78,71,69]
n=np.arange(len(month))
50
plt.bar(n,high,width=0.1,color='red',label='avg high temp')
plt.bar(n+0.1,low,width=0.1,color='blue',label='avg low
temp')
plt.bar(n+0.2,rain,width=0.1,color='olive',label='avg
rainfall')
plt.bar(n+0.3,hum,width=0.1,color='silver',label='rel
humidity')
plt.xticks(n,month)
plt.legend()
plt.title('Average data for Mumbai city')
plt.show()
51
OUTPUT:
52
20.PLOT THE FOLLOWING DATA USING A LINE PLOT:
CODE:
import pandas as pd
import matplotlib.pyplot as plt
a=[2000,2800,3000,2500,2300,2500,1000]
n=['mon','tue','wed','thu','fri','sat','sun']
plt.plot(n,a,color='Magenta',linestyle='--
',marker='H',markersize=7)
plt.xlabel('Days')
plt.ylabel('Tickets sold')
plt.show()
53
OUTPUT:
54
21.CREATE A HISTOGRAM SHOWING NUMBER OF EMPLOYEES IN
SPECIFIC AGE GROUP:
EMP_AGES= [24,45,30,59,58,56,57,45,43,43,50,40,34,33,25,19]
BINS= [0,10,20,30,40,50,60]
SPECIFY THE FOLLOWING:
1.XLABEL, YLABEL, TITLE.
2.COLOR, EDGECOLOR.
3.CHANGE THE TYPE TO STEPFILLED.
CODE:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
emp_ages=[24,45,30,59,58,56,57,45,43,43,50,40,34,33,25,19]
bins=[0,10,20,30,40,50,60]
plt.hist(emp_ages,bins,histtype='stepfilled',color='blue',edgeco
lor='black')
plt.xlabel('age')
plt.ylabel('number of people')
plt.title('Ages of Employees')
plt.show()
55
OUTPUT:
56
Program 22
57
desc employee;
+--------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------+------+-----+---------+-------+
| eno | int(11) | NO | PRI | NULL | |
| ename | varchar(20) | NO | | NULL | |
| sal | decimal(10,2) | YES | | NULL | |
| comm | decimal(10,2) | YES | | NULL | |
| deptno | int(11) | YES | | NULL | |
| job | varchar(10) | YES | | NULL | |
| doj | date | YES | | NULL | |
+--------+---------------+------+-----+---------+-------+
58
Program 23
a)Display the names and price of all the products in the store
b) Display the names of all the products with price less
than Rs.20000.00 c) Display details of all the products
with price in the range 20000 to 30000 d) Display names of
all products by the select manufacturer “Fit Express” e)
Add a new row for product with the details:
“P106”,“Vibro Exerciser”, 23000, manufacturer : null.
f) Display details of all products with manufacturer
name starting with “A” g) Display details of all products
with manufacturer name not ending with “s” h) Display
all rows sorted in descending order of price.
i)Display the name and price where manufacturer is null
j) Display the name and price where manufacturer is not null
k) Display manufacturer, whose name has 10 characters
l) Display manufacturer, whose name not starting with A alpha-
bet.
m) Display the price of items where manufacturer is Avon fitness
.
n) display product name where manufacturer details are not en-
tered.
o) display product name and manufacturer details for all prod-
ucts with manufacturer details.
59
select Prname,Unit_price from gym;
+-------------------+------------+
| Prname | Unit_price |
+-------------------+------------+
| cross trainer | 22500 |
| treadmill | 28800 |
| message chair | 18000 |
| vibration trainer | 19800 |
| bike | 11700 |
| vibro exerciser | 20700 |
+-------------------+------------+
60
select * from gym where manufacturer like 'a%';
+--------+-------------------+------------+--------------+
| Prcode | Prname | Unit_price | Manufacturer |
+--------+-------------------+------------+--------------+
| 101 | cross trainer | 22500 | avon fitness |
| 102 | treadmill | 28800 | ag fitline |
| 104 | vibration trainer | 19800 | avon fitness |
+--------+-------------------+------------+--------------+
61
| manufacturer |
+--------------+
| ag fitline |
| fitexpress |
| fitexpress |
+--------------+
62
Program 24
63
create table charity(P_Id int,LastName varchar(15),FirstName
varchar(15),Adress varchar(25), City varchar(10), Contribution
decimal(6,2));
insert into charity values(1,'Bindra','Jaspreet','5B,Gomti
Nagar','Lucknow',3500.50);
insert into charity
values(2,'Rana','Monica','21A,Bandra','Mumbai',2768);
insert into charity values(3,'Singh','Jatinder','8,Punjabi
64
Bagh','Delhi',2000.50);
insert into charity values(4,'Arora','Satinder','K/1,Shere Punjab
Colony','Mumbai',1900);
insert into charity values(5,'Krishnan','Vineeta','A-75,Adarsh
Nagar',null,null);
65
select length(Adress),P_Id from charity;
+----------------+------+
| length(Adress) | P_Id |
+----------------+------+
| 14 | 1 |
| 10 | 2 |
| 14 | 3 |
| 23 | 4 |
| 17 | 5 |
+----------------+------+
66
select concat(rtrim(FirstName),ltrim(LastName)) from charity;
+------------------------------------------+
| concat(rtrim(FirstName),ltrim(LastName)) |
+------------------------------------------+
| JaspreetBindra |
| MonicaRana |
| JatinderSingh |
| SatinderArora |
| VineetaKrishnan |
+------------------------------------------+
67
Program 25
68
insert into blockchain values(3,'Nimisha',567,'#wert5','2020-05-06');
insert into blockchain values(4,'Pihu',678,'%rtyu','2022-07-13');
insert into blockchain values(5,'Kopal',768,'rrt4%','2021-05-15');
insert into blockchain values(7,'Palakshi',534,'wer@3','2022-11-29');
69
+----------------+
| substr(user,3) |
+----------------+
| eve |
| esha |
| misha |
| hu |
| pal |
| lakshi |
+----------------+
select
id,monthname(transaction_date),dayname(transaction_date)
from blockchain;
+------+-----------------------------+---------------------------+
| id | monthname(transaction_date) | dayname(transaction_date)
|
+------+-----------------------------+---------------------------+
| 1 | September | Saturday |
| 2 | March | Tuesday |
| 3 | May | Wednesday |
| 4 | July | Wednesday |
| 5 | May | Saturday |
| 7 | November | Tuesday |
+------+-----------------------------+---------------------------+
select
user,monthname(transaction_date),year(transaction_date) from
blockchain where user like '%a';
+---------+-----------------------------+------------------------+
| user | monthname(transaction_date) | year(transaction_date) |
+---------+-----------------------------+------------------------+
| Meesha | March | 2021 |
| Nimisha | May | 2020 |
+---------+-----------------------------+------------------------+
70
select user,instr(user,'a') 'position' from blockchain;
+----------+----------+
| user | position |
+----------+----------+
| Steve | 0|
| Meesha | 6|
| Nimisha | 7|
| Pihu | 0|
| Kopal | 4|
| Palakshi | 2|
+----------+----------+
71
Program 26
72
4. Display type and total quantity of each type of shoes and
display only those type where average size is greater than 5.5.
5. Display type and total quantity of each type of shoes where
size is not equal to 6 and total quantity is greater than 1500.
6. Display the type, size, total count from shoes for each type
and with that each size.
(group by multiple columns)
7. Display the total stock value(cost*qty) of each type of
shoes. Arrange it in ascending order of total stock value
. Give alias name as ‘Total stock value’.
8. Display the count of total number of different types of
shoes available in shoes table.
73
+--------+----------+
74
+-------------------+
| Total stock value |
+-------------------+
| 245715.5555550198 |
| 253244.4444437396 |
| 447868.7500000000 |
+-------------------+
Program 27
Create tables(Emp and Dept) with following constraints AND in-
sert 5 records in emp table and dept table.
Table emp
sal int
Table dept
deptno int primary key
dname char(10)
location char(30)
Insert following Records:
EMP
+-----+-------+------+----------+
75
| eno | ename | dno | sal |
+-----+-------+------+----------+
| 101 | A | 10 | 10000.00 |
| 102 | B | 20 | 20000.00 |
| 103 | C | NULL | 30000.00 |
| 104 | D | 10 | 5000.00 |
| 105 | E | 30 | 50000.00
DEPT
+-----+-------+--------+
| dno | dname | loc |
+-----+-------+--------+
| 10 | FIN | NM |
| 20 | mkt | delhi |
| 30 | admin | nm |
| 40 | RES | Jaipur |
| 50 | Sales | Jaipur |
Write SQL commands to:
2. Display ename,dname and department number from both ta-
bles.
from emp,dept
where dept.deptno=emp.deptno
group by emp.deptno
76
create table emp(empno int primary key,ename char(20),deptno
int,sal int);
insert into emp values(101,'A',10,10000);
insert into emp values(102,'B',20,20000);
insert into emp values(103,'C',null,30000);
insert into emp values(104,'D',10,5000);
insert into emp values(105,'E',30,50000);
create table dept(deptno int primary key,dname
char(10),location char(30));
insert into dept values(10,'FIN','NM');
insert into dept values(20,'mkt','delhi');
insert into dept values(30,'admin','NM');
insert into dept values(40,'RES','Jaipur');
insert into dept values(50,'Sales','Jaipur');
77
emp.deptno=dept.deptno and sal>1000 and sal<40000 order by sal
desc;
+-------+--------+----------+
| ename | deptno | location |
+-------+--------+----------+
|B | 20 | delhi |
|A | 10 | NM |
|D | 10 | NM |
78