0% found this document useful (0 votes)
226 views65 pages

ST Joseph'S Convent Senior Secondary School: Name:-Shatakshi Gaur Class:-Xii Sec:-A Board Roll No.

The document provides an index and programs for a practical file on data handling, data visualization, and general programs using Python pandas and Matplotlib libraries. It includes 6 programs on data handling such as creating pandas series and data frames, filtering rows, and importing/exporting CSV files. It also includes 3 programs on data visualization like subject-wise analysis of exam results and plotting charts from data frames. Finally, it lists 5 general programs involving population and income data, creating and manipulating data frames, plotting histograms, and more. The programs demonstrate skills in data wrangling, analysis, and visualization using key Python libraries.

Uploaded by

Navjeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
226 views65 pages

ST Joseph'S Convent Senior Secondary School: Name:-Shatakshi Gaur Class:-Xii Sec:-A Board Roll No.

The document provides an index and programs for a practical file on data handling, data visualization, and general programs using Python pandas and Matplotlib libraries. It includes 6 programs on data handling such as creating pandas series and data frames, filtering rows, and importing/exporting CSV files. It also includes 3 programs on data visualization like subject-wise analysis of exam results and plotting charts from data frames. Finally, it lists 5 general programs involving population and income data, creating and manipulating data frames, plotting histograms, and more. The programs demonstrate skills in data wrangling, analysis, and visualization using key Python libraries.

Uploaded by

Navjeet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

ST JOSEPH’S

CONVENT SENIOR
SECONDARY
SCHOOL

NAME:-SHATAKSHI GAUR
CLASS:-XII SEC:-A
BOARD ROLL NO.:-
INFORMATICS
PRACTICES (065)
PRACTICAL FILE
2020-2021
INDEX
DATA HANDLING
S.NO. PROGRAMS
1. Create a pandas series from a dictionary of
values and a ndarray.
2. Given a Series, print all the elements that
are above the 75th percentile.
3. 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.
4. Create a data frame for examination result
and display row labels, column labels data
types of each column and the dimensions
5. Filter out rows based on different criteria
such as duplicate rows.
6. Importing and exporting data between
pandas and CSV file.
DATA VISUALISATION
S.NO. PROGRAMS
7. Given the school result data, analyses the
performance of the students on different
parameters, e.g subject wise or class wise.
8. For the Data frames created above,
analyze, and plot appropriate charts with
title and legend.
9. Take data of your interest from an open
source (e.g. data.gov.in), aggregate and
summarize it. Then plot it using different
plotting functions of the Matplotlib library.

GENERAL PROGRAMS
S.NO. PROGRAMS
10. Object1 Population stores the details of
population in four metro cities of India and
Object2 AvgIncome stores the total average
income reported in previous year in each of
these metros. Calculate income per capita for
each of these metro cities.
11 Write a program to create a Data frame to store
weight, age and names of 3 people. Print the
Data frame and its transpose.
Create two Data frames df1 and df2 having
12
team points of two teams, write a program to
list maximum points till that round
(cumulatively).
13 Write a program to create a data frame namely
newDf that stores all the rows of saleDf2 and
only the matching indexes rows from saleDf1
Write a program to plot a bar chart from the
14
medals won by Australia. In the same chart, plot
medals won by India too.
Prof Awasthi is doing some research in the field
15
of environment. For some plotting purposes, he
has generated some data as:
Mu=100, Sigma=15
X=mu + sigma
*numpy.random.randn(10000). Write a
program to plot this data on a horizontal
histogram.

DATA MANAGEMENT-15 QUERIES


DATA HANDLING

PROGRAM 1
AIM: Create a pandas series from a dictionary of values
and a ndarray.
CODE:
#Using Dictionary
#import pandas as pd
import pandas as pd
#import numpy as np
import numpy as np
#simple dictionary
val={"G":1,"H":2,"A":3,"R":6,"D":8,"S":1,"K":1}
ser1=pd.Series(val) #forming series
print("DICTIONARY :")
print(ser1) #output
print() #space
#Using Numpy
arr=np.array(['S','D','A','Q','B','F','K','G','H','E'])
print("NDARRAY :")
ser2=pd.Series(arr) #forming series
print(ser2) #output
OUTPUT
DICTIONARY :
G 1
H 2
A 3
R 6
D 8
S 1
K 1
dtype: int64

NDARRAY :
0 S
1 D
2 A
3 Q
4 B
5 F
6 K
7 G
8 H
9 E
dtype: object
PROGRAM 2
AIM: Create a Series, print all the elements that are
above the 75th percentile

CODE:
#import pandas as pd
import pandas as pd
#import numpy as np
import numpy as np
#Using Numpy
arr=np.array([42,12,72,85,56,100,79,73,69,31,87,96,10
0]) #Numpy array
ser1=pd.Series(arr) #forming series
quantile_value=ser1.quantile(q=0.75)
print("75th Percentile is:",quantile_value)
print("Values that are greater than 75th percentile:")
for val in ser1:
if (val>quantile_value):
print(val,end=" ")
OUTPUT:

75th Percentile is: 87.0


Values that are greater than 75th percentile:
100 96 100
PROGRAM 3
AIM: 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.

CODE:
import pandas as pd
sales_data={
"Item Category":["Food","Drink","Food","Drink",
"Sweets","Food","Drink"],
"Item Name":["Biscuits","Pepsi","Bread","Cocacola"
, "Rasgulla","Butter","Butter Milk"],
"Expenditure": [100,30,80,200,80,100,300]
}
sales_quaterly=pd.DataFrame(sales_data)
print(sales_quaterly)
gdf=sales_quaterly.groupby("Item Category")
resulted_df=gdf["Expenditure"].sum()
print(resulted_df)
pivoted_df=sales_quaterly.pivot_table(index="Item
Category",values="Expenditure",aggfunc="sum")
print(pivoted_df)
OUTPUT:
Item Category Item Name Expenditure
0 Food Biscuits 100
1 Drink Pepsi 30
2 Food Bread 80
3 Drink Cocacola 200
4 Sweets Rasgulla 80
5 Food Butter 100
6 Drink Butter Milk 300
Item Category
Drink 530
Food 280
Sweets 80
Name: Expenditure, dtype: int64
Expenditure
Item Category
Drink 530
Food 280
Sweets 80
PROGRAM 4
AIM: Create a Data Frame for examination result and
display row labels, coloumn labels data types of each
column and the dimensions.
CODE:
import pandas as pd
result_data={
'Eng': [90,85,72,69,86],
'Phy': [85,82,73,56,96],
'Chem': [88,65,70,36,35],
'Maths': [90,56,45,36,42],
'Comp Sci': [85,85,65,23,66],
'Marks':[406,450,390,480,450],
'Percent': [96,85,48,79,68] }
result_df=pd.DataFrame(result_data,
index=["Amit","Sohan","Mohan","Neha","Sachin"])
print(result_df)
print(result_df.index)
print(result_df.columns)
print(result_df.dtypes)
print(result_df.ndim)
print(result_df.size)
print(result_df.shape)
print(result_df.T)
OUTPUT:
Eng Phy Chem Maths Comp Sci Marks Percent
Amit 90 85 88 90 85 406 96
Sohan 85 82 65 56 85 450 85
Mohan72 73 70 45 65 390 48
Neha 69 56 36 36 23 480 79
Sachin 86 96 35 42 66 450 68
Index(['Amit', 'Sohan', 'Mohan', 'Neha', 'Sachin'],
dtype='object')
Index(['Eng', 'Phy', 'Chem', 'Maths', 'Comp Sci', 'Marks',
'Percentage'], dtype='object')
Eng int64
Phy int64
Chem int64
Maths int64
Comp Sci int64
Marks int64
Percentage int64
dtype: object
2
35
(5, 7)
Amit Sohan Mohan Neha Sachin
Eng 90 85 72 69 86
Phy 85 82 73 56 96
Chem 88 65 70 36 35
Maths 90 56 45 36 42
CompSci 85 85 65 23 66
Marks 406 450 390 480 450
Percent 96 85 48 79 68
PROGRAM 5
AIM: Filter out rows based on different criteria such as
duplicate rows.
CODE:
import pandas as pd
data={
"Item Name": ["Biscuits", "Chocolate", "Biscuit",
"Cocacola", "Pen", "Biscuit", "Book", "Pen", "Laptop",
"Bulb"],
"Price": [100,100,100,200,30,150,500,15,24000,85],
"Category":["Food", "Food", "Food", "Drink", "Education",
"Wheat Items", "Education", "Education", "Electronics",
"Electricals"],
"Location": ["Delhi", "Delhi", "Delhi", "Jaipur", "Jaipur",
"Bengaluru", "Bengaluru", "Mumbai", "Mumbai", "Delhi"]}
df=pd.DataFrame(data)
print(df)
print("All the duplicate rows:")
print(df[df.duplicated()])
print("Duplicate rows on the basis of Item Name
column:")
print(df[df.duplicated(['Item Name'])])
print("Duplicate rows on the basis of Item Name and
Location column:")
print(df[df.duplicated(['Item Name','Location'])])
print("Duplicate rows on the basis of Item Name and
Category column:")
print(df[df.duplicated(['Item Name','Category'])])
OUTPUT:
Item Name Price Category Location
0 Biscuits 100 Food Delhi
1 Chocolate 100 Food Delhi
2 Biscuit 100 Food Delhi
3 Cocacola 200 Drink Jaipur
4 Pen 30 Education Jaipur
5 Biscuit 150 Wheat Items Bengaluru
6 Book 500 Education Bengaluru
7 Pen 15 Education Mumbai
8 Laptop 24000 Electronics Mumbai
9 Bulb 85 Electricals Delhi
All the duplicate rows:
Empty DataFrame
Columns: [Item Name, Price, Category, Location]
Index: []
Duplicate rows on the basis of Item Name column:
Item Name Price Category Location
5 Biscuit 150 Wheat Items Bengaluru
7 Pen 15 Education Mumbai
Duplicate rows on the basis of Item Name and Location
column:
Empty DataFrame
Columns: [Item Name, Price, Category, Location]
Index: []
Duplicate rows on the basis of Item Name and Category
column:
Item Name Price Category Location
7 Pen 15 Education Mumbai
PROGRAM 6
AIM: Importing and exporting data between pandas
and CSV file.
CODE:
import pandas as pd
edf=pd.read_csv(“c:\\pywork\\Employ ee.csv”,\
names=[‘EmpID’,’EmpName’,’Designati on’,
’Salary’],skiprows=1) print(edf)
print(“Maximum salary is”,edf.Salary.max())
OUTPUT:
EmpID EmpName Designation Salary
0 1001 Trupti Manager 56000
1 1002 Raziya Manager 55900
2 1003 Simran Analyst 35000
3 1004 Silviya Clerk 25000
4 1005 Suji PR Officer 31000
Minimum salary is 56000
Visualization
PROGRAM 7
AIM: Given the school result data, analyses the
performance of the students on different parameters,
e.g subject wise or class wise.
CODE:
import numpy as np
import matplotlib.pyplot as plt
# data to plot
n_groups = 5
boys = (92, 90, 93, 98, 97)
girls = (95, 92, 90, 95, 96)
# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
rects1 = plt.bar(index, boys, bar_width,
alpha=opacity,
color='g',
label='Boys')
rects2 = plt.bar(index + bar_width, girls, bar_width,
alpha=opacity,
color='r',
label='Girls')
plt.xlabel('Person')
plt.ylabel('Scores')
plt.title('Scores by person')
plt.xticks(index + bar_width, ('2016', '2017', '2018',
'2019', '2020'))
plt.legend()
plt.tight_layout()
plt.show()
OUTPUT:
PROGRAM 8
AIM: For the Data frames created above, analyze, and
plot appropriate charts with title and legend.
CODE:
import matplotlib.pyplot as plt
import numpy as np
s=['1st','2nd','3rd']
per_sc=[95,89,77]
per_com=[90,83,75]
per_hum=[97,92,77]
x=np.arange(len(s))
plt.bar(x,per_sc,label="SCIENCE",width=0.25,color='gre
en')
plt.bar(x+0.25,per_com,label="COMMERCE",width=0.2
5,color='red')
plt.bar(x+0.50,per_hum,label="HUMANITIES",width=0.
25,color='gold')
plt.xticks(x,s)
plt.xlabel('POSITION')
plt.ylabel('PERCENTAGE')
plt.title('BAR GRAPH FOR RESULT ANALYSIS')
plt.legend()
plt.show()
OUTPUT:
PROGRAM 9
AIM: Take data of your interest from an open source
(e.g. data.gov.in), aggregate and summarize it. Then
plot it using different plotting functions of the
Matplotlib library.

CODE:
import pandas as pd
dataframe=pd.read_csv("C:/Users/navjeet/Desktop/sc
ottish_hills.csv")
print(dataframe)

import pandas as pd
import matplotlib.pyplot as plt
dataframe=pd.read_csv("C:/Users/navjeet/Desktop/sc
ottish_hills.csv")
x=dataframe.Height
y=dataframe.Latitude
plt.scatter(x, y)
plt.show()
OUTPUT:
PROGRAM 10
AIM: Object1 Population stores the details of
population in four metro cities of India and Object2
AvgIncome stores the total average income reported in
previous year in each of these metros. Calculate
income per capita for each of these metro cities.
CODE:
import pandas as pd
population=pd.Series([10927986,12691836,4631392,4
328063],index=['Delhi','Mumbai','Kolkata','Chennai'])
avgincome=pd.Series([7216789011,45167390826,9086
723451,1132250967],
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 capia income in four metro cities')
print(percapita)
OUTPUT:

population in four metro cities


Delhi 10927986
Mumbai 12691836
Kolkata 4631392
Chennai 4328063
dtype: int64
Avg income in four metro cities
Delhi 7216789011
Mumbai 45167390826
Kolkata 9086723451
Chennai 1132250967
dtype: int64
Per capia income in four metro cities
Delhi 660.395155
Mumbai 3558.775171
Kolkata 1961.985393
Chennai 261.606859
dtype: float64
PROGRAM 11
AIM: Write a program to create a Data frame to store
weight, age and names of 3 people. Print the Data
frame and its transpose.
CODE:
import pandas as pd
df=pd.DataFrame({'Age':
[29,20,25],
'Weight':
[56,60,55],
'Names':
['Elena','Caroline','Smith']})
print('Original Dataframe')
print(df)
print('Transposed Dataframe')
print(df.T)
OUTPUT:

Original Dataframe
Age Weight Names
0 29 56 Elena
1 20 60 Caroline
2 25 55 Smith
Transposed Dataframe
0 1 2
Age 29 20 25
Weight 56 60 55
Names Elena Caroline Smith
PROGRAM 12
AIM: Create two Data frames df1 and df2 having team
points of two teams, write a program to list maximum
points till that round (cumulatively).

CODE:
import pandas as pd
df1=pd.DataFrame({'p1':
[700,975,970,900],
'p2':
[490,460,570,590]})
df2=pd.DataFrame({'p1':
[1100,1275,1270,1400],
'p2':
[1400,1260,1500,1190]})
print('Team1')
print(df1.cummax())
print('Team2')
print(df2.cummax())
OUTPUT:
Team1
p1 p2
0 700 490
1 975 490
2 975 570
3 975 590
Team2
p1 p2
0 1100 1400
1 1275 1400
2 1275 1500
3 1400 1500
PROGRAM 13
AIM: Write a program to create a data frame namely
newDf that stores all the rows of saleDf2 and only the
matching indexes rows from saleDf1.

CODE:
import pandas as pd
dic={'Target':
[56000,70000,75000,60000],
'Sales':
[58000,68000,78000,61000]}
df1=pd.DataFrame(dic,index=['zoneA','zoneB','zoneC','z
oneD'])
dic2={'Name':
['east','west','middle','north','south','rural'],
'product':
['oven','AC','AC','oven','TV','tubewell']}
df2=pd.DataFrame(dic2,index=['zoneA','zoneB','zoneC',
'zoneD','zoneE','zoneF'])
Newdf=df2.join(df1)
print(Newdf)
OUTPUT:
Name product Target Sales
zoneA east oven 56000.0 58000.0
zoneB west AC 70000.0 68000.0
zoneC middle AC 75000.0 78000.0
zoneD north oven 60000.0 61000.0
zoneE south TV NaN NaN
zoneF rural tubewell NaN NaN
PROGRAM 14
AIM: Write a program to plot a bar chart from the
medals won by Australia. In the same chart, plot
medals won by India too.
CODE:
import matplotlib.pyplot as plt
info=['Gold','Silver','Bronze','Total']
Australia=[80,59,59,198]
India=[26,20,20,66]
plt.bar(info,Australia,color='yellow')
plt.bar(info,India,color='blue')
plt.xlabel('Medals')
plt.ylabel('Australia , India medal count')
plt.show()
OUTPUT:
PROGRAM 15
AIM: Prof Awasthi is doing some research in the field
of environment. For some plotting purposes, he has
generated some data as:
Mu=100, Sigma=15
X=mu + sigma
*numpy.random.randn(10000). Write a program to
plot this data on a horizontal histogram.

CODE:
import numpy as np
import matplotlib.pyplot as plt
mu=100
sigma=15
x=mu + sigma*np.random.randn(10000)
plt.hist(x,bins=30,orientation='horizontal')
plt.title('Research data histogram')
plt.show()
OUTPUT:
DATA MANAGEMENT

PROGRAM 1
AIM: Create a student table with the student id, name,
and marks as attributes where the student id is the
primary key.

CODE:
create table student (studentID int primary key, Name
varchar(20), Marks int);
PROGRAM 2
AIM: Insert the details of a new student in the above
table.

CODE:
insert into student values (234, 'Nanny', 80);
insert into student values (235, 'Palak', 70);
insert into student values (236, 'Racheal', 95);
insert into student values (237, 'Joey', 68);
insert into student values (238, 'Emma', 77);
OUTPUT:

| studentID | Name | Marks |


+-----------+---------+-------+
| 234|Nanny |80 |
| 235 | Palak | 70 |
| 236 | Racheal | 95 |
| 237 | Joey | 68 |
| 238 | Emma | 77 |
+-----------+---------+-------+
PROGRAM 3
AIM: Delete the details of a student in the above table.

CODE:
delete from student where Name='Nanny';
OUTPUT:

| studentID | Name | Marks |


+-----------+---------+-------+
| 235 | Palak | 70 |
| 236 | Racheal | 95 |
|237 | Joey | 68 |
| 238 | Emma | 77 |
+-----------+---------+-------+
PROGRAM 4
AIM: Use the select command to get the details of the
students with marks more than 80.

CODE:
select*from student where Marks>70;
OUTPUT:

+-----------+---------+-------+
| studentID | Name | Marks |
+-----------+---------+-------+
| 236 | Racheal | 95 |
| 238 | Emma | 77 |
| 239 | Sahil | 90 |
+-----------+---------+-------+
3 rows in set (0.00 sec)
PROGRAM 5
AIM: Find the min, max, sum, and average of the marks
in a student marks table.

CODE:
select min(Marks) from student;
select max(Marks) from student;
select sum(Marks) from student
OUTPUT:

+------------+
| min(Marks) |
+------------+
| 68 |
+------------+

+------------+
| max(Marks) |
+------------+
| 95 |
+------------+

+------------+
| sum(Marks) |
+------------+
| 400 |
+------------+
PROGRAM 6
AIM: Find the total number of customers from each
country in the table (customer ID, customer Name,
country) using group by.

CODE:
Select count(name), country from customer group by
country;
OUTPUT:
+-------------+-----------+
| count(name) | country |
+-------------+-----------+
| 3 | Australia |
| 1 | America |
| 2 | India |
+-------------+-----------+
PROGRAM 7
AIM: Write a SQL query to order the (student ID,
marks) table in descending order of the marks.

CODE:
select*from student order by marks asc;
OUTPUT:

+-----------+---------+-------+
| studentID | Name | Marks |
+-----------+---------+-------+
| 237 | Joey | 68 |
| 235 | Palak | 70 |
| 238 | Emma | 77 |
| 239 | Sahil | 90 |
| 236 | Racheal | 95 |
+-----------+---------+-------+
PROGRAM 8
AIM: .Display the name of all games with their gcodes
from the table games.

Table:Games
+-------+--------------+---------+--------+------------+--------------+
| gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+

CODE:
select gcode, GameName from games;
OUTPUT:
+-------+--------------+
| gcode | GameName |
+-------+--------------+
| 101 | carom board |
| 102 | badminton |
| 103 | table tennis |
| 105 | chess |
| 108 | lawn tennis |
+-------+--------------+
5 rows in set (0.00 sec)
PROGRAM 9
AIM: . Display details of those game which are having
prize money more than 7000.

Table:Games
+-------+--------------+---------+--------+------------+--------------+
| gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+

CODE:
select*from games where PrizeMoney>7000;
OUTPUT:
+-------+--------------+---------+--------+------------+--------------+
| gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+
4 rows in set (0.00 sec)
PROGRAM 10
AIM: . Display the content of the games table in
ascending order of schedule date.
Table:Games
+-------+--------------+---------+--------+------------+--------------+
| gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+

CODE:
select*from games order by ScheduleDate;
OUTPUT:
+-------+--------------+---------+--------+------------+--------------+ |
gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+
5 rows in set (0.00 sec)
PROGRAM 11
AIM: . Display sum of prize money for each type of
game.
Table:Games
+-------+--------------+---------+--------+------------+--------------+
| gcode | GameName | type | number | PrizeMoney | ScheduleDate |
+-------+--------------+---------+--------+------------+--------------+
| 101 | carom board | indoor | 2 | 5000 | 2004-01-23 |
| 102 | badminton | outdoor | 2 | 12000 | 2003-12-12 |
| 103 | table tennis | indoor | 4 | 8000 | 2004-02-14 |
| 105 | chess | indoor | 2 | 9000 | 2004-01-01 |
| 108 | lawn tennis | outdoor | 4 | 25000 | 2004-03-19 |
+-------+--------------+---------+--------+------------+--------------+

CODE:
select sum(PrizeMoney), type from games group by
type;
OUTPUT:
+-----------------+---------+
| sum(PrizeMoney) | type |
+-----------------+---------+
| 22000 | indoor |
| 37000 | outdoor |
+-----------------+---------+
2 rows in set (0.00 sec)
PROGRAM 12
AIM: . Display the names of all the white colored
vehicles.

Table : cabhub
+-------+-------------+----------+--------+----------+---------+
| vcode | VehicleName | make | color | capacity | charges |
+-------+-------------+----------+--------+----------+---------+
| 100 | innova | toyota | white | 7 | 15 |
| 102 | sx4 | suzuki | blue | 4 | 14 |
| 104 | c class | mercedes | red | 4 | 35 |
| 105 | a star | suzuki | white | 3 | 14 |
| 108 | indigo | tata | silver | 3 | 12 |
+-------+-------------+----------+--------+----------+---------+

CODE:
select VehicleName from cabhub where color = 'white';
OUTPUT:
+-------------+
| VehicleName |
+-------------+
| innova | | a star |
+-------------+
2 rows in set (0.00 sec)
PROGRAM 13
AIM: . Display name of vehicle, make and capacity of
vehicles in ascending order of their seating capacity.
Table : cabhub
+-------+-------------+----------+--------+----------+---------+
| vcode | VehicleName | make | color | capacity | charges |
+-------+-------------+----------+--------+----------+---------+
| 100 | innova | toyota | white | 7 | 15 |
| 102 | sx4 | suzuki | blue | 4 | 14 |
| 104 | c class | mercedes | red | 4 | 35 |
| 105 | a star | suzuki | white | 3 | 14 |
| 108 | indigo | tata | silver | 3 | 12 |
+-------+-------------+----------+--------+----------+---------+

CODE:select VehicleName, make, capacity from cabhub


order by capacity;
OUTPUT:
+-------------+----------+----------+
| VehicleName | make | capacity |
+-------------+----------+----------+
| a star | suzuki | 3 |
| indigo | tata | 3 |
| sx4 | suzuki | 4 |
| c class | mercedes | 4 |
| innova | toyota | 7 |
+-------------+----------+----------+
PROGRAM 14
AIM: . Display the highest charges at which a vehicle
can be hired from cabhub.

Table : cabhub
+-------+-------------+----------+--------+----------+---------+
| vcode | VehicleName | make | color | capacity | charges |
+-------+-------------+----------+--------+----------+---------+
| 100 | innova | toyota | white | 7 | 15 |
| 102 | sx4 | suzuki | blue | 4 | 14 |
| 104 | c class | mercedes | red | 4 | 35 |
| 105 | a star | suzuki | white | 3 | 14 |
| 108 | indigo | tata | silver | 3 | 12 |
+-------+-------------+----------+--------+----------+---------+

CODE:
select max(charges) from cabhub;
OUTPUT:
+--------------+
| max(charges) |
+--------------+
| 35 |
+--------------+
PROGRAM 15
AIM: . Display the customer name and the
corresponding name of the vehicle hired by them.
Table : cabhub
+-------+-------------+----------+--------+----------+---------+
| vcode | VehicleName | make | color | capacity | charges |
+-------+-------------+----------+--------+----------+---------+
| 100 | innova | toyota | white | 7 | 15 |
| 102 | sx4 | suzuki | blue | 4 | 14 |
| 104 | c class | mercedes | red | 4 | 35 |
| 105 | a star | suzuki | white | 3 | 14 |
| 108 | indigo | tata | silver | 3 | 12 |
+-------+-------------+----------+--------+----------+---------+

Table:Customer2
+-------+---------------+-------+
| ccode | CName | Vcode |
+-------+---------------+-------+
| 1 | hemant sahu | 101 |
| 2 | sumit yadav | 108 |
| 3 | feroz khan | 105 |
| 4 | samuel christ | 104 |
+-------+---------------+-------+

CODE:
select CName, VehicleName from customer2, cabhub
where customer2.Vcode=cabhub.vcode;
OUTPUT:

+---------------+-------------+
| CName | VehicleName |
+---------------+-------------+
| samuel christ | c class |
| feroz khan | a star |
| sumit yadav | indigo |
+---------------+-------------+

You might also like