0% found this document useful (0 votes)
126 views40 pages

Practical File Ip Class 12

Class 12 practical file

Uploaded by

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

Practical File Ip Class 12

Class 12 practical file

Uploaded by

Sachin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 40
TABLE OF CONTENTS S.No Name of the Exercises Page.No Programs using Pandas SERIES 1. | Creating a Python program to create a series using a dictionary, 3 2, | Creating a Python program to create a series using scalar value. 4 ‘3. | Creating a Python program to create a series using numpy array. 5 4. | Creating a python program for modifying or updating existing valucs of series} 6 object. S. | Creating a Python program for performing mathematical operations on two] 7 Series objects. 6. | Creating a Python program for calculating per capita income of four zones 8 using Series. 7. | Creating a Python program to display attributes of a Series. 9 8. | Creating a Python program using head() and tail() in Series. 10 i DATAFRAME 7 9. ] Creating a Python program for creating a DataFrame using a nested list. eT 10. | Creating a Python program for creating a DataFrame using a dictionary of | 12 lists. 11. | Creating a Python program for accessing values of rows and columns of a 14 DataFrame. 12. | Creating a python program to perform operations on a DataFrame (rename,| 16 count, update, replace) 13. | Creating a Python program to filter the data of a DataFrame. 18 14. | Creating a Python program to display the attributes of the DataFrame. 19 15. | Creating a Python program to display the data ofa DataFrame row-wise and| 20 column-wise using iterrows() and iteritems() 16. | Creating a Python program to perform writing and reading operations ina] 22 CSV file. "17. | Creating a python program for plotting a line chart. 23 18. | Creating a python program for plotting a bar chart from a CSV file. 24 19. | Creating a python program for plotting a multiple bar chart froma CSVfile. | __25 20. | Creating a python program for plotting Histogram. 26 (SL Qucrico S| 21. | SQL COMMANDS EXERCISE ~ 1 (Basic Queries ~ I) 27 22. | SQL COMMANDS EXERCISE — 2 (Basic Queries — II) 29 23. | SQL COMMANDS EXERCISE — 3 (Aggregate functions, Order by Group by, | _ 31 Having Clause) 24. | SQL COMMANDS EXERCISE - 4 (Math Functions) 33 25. | SQL COMMANDS EXERCISE - 5 (Text Functions) 35 26. | SQL COMMANDS EXERCISE - 6 (Date Functions) 37 2 AIM: To write a Python program to create a Series object that stores the Initial budget allocated (50000/- cach) for the four quarters of the year: Qtrl, Qtr2, Qtr3 and Qtr4. import pandas as pd Budget=pd. Series (50000 ,index=['gtri', 'gtr2', '9tr3', 'gtr4'1) print (Budget) Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUPUT: Qtr1 — 5000¢ Qtr2 — 5000C Qtr3 — 5000¢ atr4 —5000¢ dtype: inte ATE: CREATING A PYTHON PROGRAM TO CREATE A SERIES USING A DICTIONARY. AIM: To write a Python program to create a Series to store 5 students Percentage Using dictionary and print all the elements that are above 75 percentage. SOURCE CODE: [import pandas as pd {"Arun":65,"Bala IS=pd. Series (D) print (S[S>75]) 85) 91, "Charan" :74, "Dinesh": 80, "Ushi BESULT: ‘Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT: Bala 91 Dinesh 80 Usha 85 type: inte4 HERERO IIIT TOI SIRI ROSE TTT SSIS OTIS OTITIS DATE: CREATING A PYTHON PROGRAM TO CREATE A SERIES USING NUMPY ARRAY AIM: To write a Python program to create a Series object that stores the Employee names as index and their Salary as values SOURCE CODE: import pandas as pd import numpy es np Section=['A','B','C'] Contribution=np.array([6700 ,5500,np.NaN]) S=pd . Series (data=Contribution, inde: ection) lprint (5) (RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT; A 6700.0 B 5500.0 c NaN dtype: floated Lehi nan SEIS IIIS ISAS ISI IIIS ITO I OF SERIES OBJECT. AIM: ‘To Write a Python program to create a Series object with Employee names as the index and their salaries as values. Accept the name of the employee whose salary needs to be changed, along with the new salary, and update it in the Series. Name= input("Enter the name of the employee: ") if Name in 8: new salary = float(input{"Enter the new salary: ")) S[Name] = new salary print("\nSalary updated successfully!") print("\nEmptoyees Salary After updating") print(s} else: print("\nEmployee not found in the records.") L301 " print{"\nThank Youtl!") RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. Sample Output: Employees Salary Bofore updating Jona 50000 Bala 60000 Anu 55000 Birundha 52000 type: inted Do you want to update tho sulury of tho employooly/n}?ry Enter the name of the employee: Anu Enter the new salary: 58000 Salary updated successfully! Employees Salary After updating Jona 50000 Bata 60000 Anu 58000 Birunana 52000 type: intea DATE: PERFORMING MATHEMATICAL OPERATIONS ON SERIES OBJECTS AIM: To create a program in python to perform following mathematical Operations on Two Series objects: (i) Addition (ii) Subtraction (iii) Multiplication (iv) Division. SOURCE CODE; fimport pandas as pd lsl=pd. Series (110,20,30] ,andex=['a','b’,'c']) ls2=pd. Series ( (2,5) ,index={'a','b']) [print ("The Addition of two series object is:") [print ("The Multiplication of two series object is:") print (S1*S2) jprint("rhe Division of two series object is:") jprint (S1/s2) RESULT: ‘Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT; The Addition of two series object is: a 12.0 b 25.0 © Nay type: floatsa ‘The Subtraction of two series object is: a 8.0 b 15.0 ce NaN dtype: floatsa The Multiplication of two series object is: a 20.0 b 100.0 © Nan dtype: floatsd ‘The Division of two series object 4s: a 5.0 dtype: floated To write a Python program to create two series i.e, population and average income of Four Zones, and then calculate per capita income storing in third pandas series print it. Source Code; import pandas as pd population=pd.Series{[5200,2100,4523,3422], index=[East', West’, South’ lavgincome=pd.Series{[117832,587324,171802,235038),index=[ East’, West' |perCapitaIncome=avgincome/ population print("Pereapita Income of Four Zones are:") print{"\n") print(perCapitalncome) jorth’]) South’ North'] RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. Sample Output; Percapita Income of Four Zones are: East 22.660000 West 279.678095 South 37.984081 North 68.684395 type: floated TERED HEE ERED DISET SITIES TUS AIT DI DIA. CRE: AIM: To write a Python program to create a Series using list and display the following attributes of the Series: (i) index (ii) dtype (iii) size (iv) shape (v) hasnans SOURCE CODE: import pandas as pd ln=[10,45,67,3,43] s=pd. Series (L,index=['a','b’,‘c','d','e'l) Jprint ("the index of the Series is:",5.dndex) lprint ("the data type of the Series is:",S.dtype) lprint(""The size of the Series is:",S.size) lprant("The shape of the Series is:",S.shape) lprint("The NaN of the Series is:",S.hasnans) ‘RESULT: ‘Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT: The index of the Series is: Index({'a', 'b', 'c', The data type of the Series is: int64 ‘The size of the series is: 5 ‘The shape of the Series is: (5,) ‘The NaN of the Series is: False te'], dtype='cbject") DATE: CREATING A PYTHON PROGRAM USING head{) AND tail() IN SERIES. AIM: To write a Python program to create a Series using list of Marks of 10 students and display first 5 Students’ marks and Last 2 Students’ marks from Series object. SOURCE CODE: fisport pandas as pa Marks=[67,09,90,66,100,45,83,43,66,55) s=pd.seraes (Marks, index=[‘stul',‘Stu2', ‘stu’, "stud", 'Stu5', "stu6", ‘stu7, ‘stus', "stus Jorint("The First five student marks are: Jorint (6-head()) fprant ("\n") lp Thus, the above Python program has been executed successfully, and the output has been verified. ‘SAMPLE OUTPUT: The First five student marks are: stu 67 Stuz 89 stu3 90 stus 86 stu5 100 dtype: intéd The Last two students marks are: stud 66 stul0 55 type: inte To write a Python program to create a panda’s Data Frame for the following table Using Nested list: Name | Age stu [arun 21 Stu2_ [Bala 23 Stu3__ [Charan 22 SOURCE CODE: import pandas as pd L=[['Arun',21],['Bala',23], ['Charan',22]] D=pd.DataFrame (L,index=['stul', 'Stu2', 'Stu3'],columns=['Name', 'Age']) print (D) RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. Si ol H Name Age stul Arun 21 stu2 Bala 23 stu3 Charan 22 DATE: CREATING A PYTHON PROGRAM FOR ACCESSING VALUES OF ROWS AND COLUMNS OF A DATAFRAME, AIM: To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: (i) To Display only column ‘Toys’ from DataFrame DF. (ii) To Display the row details of ‘AP’ and ‘OD from DataFrame DF. (iii) To Display the column 'Books' and 'Uniform' for 'M.P' and 'U.P’ from DataFrame DF. (iv) To Display consecutive 3 rows and 3 columns from DataFrame DF. SOURCE CODE: import pandas as pd Ib=( ‘toys ': [7916, 8808, 7226, 7517}, "Books : (61896 ,8208, 6149, 61571, ‘Uniform! : (610,508, 611,4571, "Shoes : (8210, 6798, 9611,6457)) lor=pd.patarrame(p,index=['AP', ‘0b, 'M.P', 'U.P' I) Jprint ("rhe detaiis of Toys a print (DF.loc{:, ‘Toys'1) print ("\n") Jprint (The details of AP and oD are:") print (DF.1oc{'AP':'0D', 1) print ("\n") Jprint ("The detaiis of print (DF.20c['M.P':'U. lprint("\a") Jprint (‘Consecutive 3 Rows and 3 Columns are:'} lprint (DF.410c[0:3,0:31) » Books! :'Uniform'}) RESULT: Thus. the abave Puthan nraeram has heen eveonted enececefinthr and the mitnnt has ‘SAMPLE OUTPUT; The details of Toys are RP 7916 oD 508 MP 7226 U.P 7617 Name: Toys, dtype: int64 The detaile of AP and oD are: Toys Books Uniform shoes AP 7916 61896 610 8810 op 8508 8208 508 6798 ‘The details of MP and U.P are: Books Uniform MP 6149 611 U.P 6157 457 Consecutive 3 Rows and 3 Columns are: Toys Books Uniform AP 7916 61896 610 op 8508 8208 508 M.P 7226 6149 611 Hani OnE ISSO OREO DISTRESS RAIA SET 13 CREATING A PYTHON PROGRAM FOR ACCESSING VALUES OF ROWS AND COLUMNS. OF A DATAFRAME. AIM: ‘To write a Python program to create a panda’s DataFrame called DF for the following table Using Dictionary of List and perform the following operations: (i) Insert a new column “Bags” with values as [5891, 8628, 9785, 4475]. (ii) Delete the row details of M.P from DataFrame DF. SOURCE CODE: import pandas as pd ID={'Toys' : [7916, 8508, 7226,7617] , ‘Books ':[61896,8208,6149,6157), 'Uniform':[6L0, 508,611,457], 'shoes':[8810, 6798 , 9611,6457) } Ipr=pd.DataFrame(D,index=['AP','0D','M.P','U.P'}) F['Bags']=[5891, 8628, 9785, 4475] # Adding a new column Bags| int ("After Adding a new column:") ") IS=DF.drop('M.P') # Deleting M.P details. int ("After Deleting M.P details:") ant (5; RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT; After Adding a new column: Toys Books Uniform shoes Bags AP 7916 61896 610 8810 5891 oD 8508 8208 508 6798 8628 M.P 7226 6149 611 9611 9785 U.P 7617 6157 457 6457 4475 After Deleting M.P details: Toys Books Uniform Shoes Bags AP 7916 61896 610 9810 5691 oD 8506 8208 508 6798 8628 U.P 7617 6157 457 6457 4475 enna nT IIA RIT III I To write a Python program to create a pandas DataFrame to analyze number of Government and Private medical college and their Total seats,Fees statewise details using the dataset available at www.data.gov.in. Also, perform the following operations. (i) To Change the name of the state AP to Andhra. i) To Count and Display Non-NaN values of each column. To Count and Display Non-NaN values of each row. liv) To Increase the fees of all colleges by 5% (v) To Replace all NaN values with 0. Source Code: ratowlse Go val eEee import pandas as pd import aumpy as ap |$1=pd.Series{{17,30,7150,25000} index=['GC |$2=pd.Series({6 np.NaN,726,33000}.index=[GC"PC )$3=pd.Series({np.NaN,1,100,27000],index=[ GC’ es] AIMS AIMS :S5)) DF=pd.DataFrame({ AP :51, Assam :S2, Sikkim':S3, 7) int(*Original DataFrame") print("Changiag the name from AP to Andhra:") DF.rename(columas=[AP's"Andhra"jinplace=Truc) print(DF] print("\n") print("Counting und displaying non-NaN values of each column:") int(DF.count{)) print("\n") print("Counting and displaying non-NaN values of each ro print(DF.count{1)) print("\n") print(“Increasing the fe: DE .toc[ Fees':]=DF.toc[ Fe: ofall colleges by 5%") }*DF.loc[ Fees'y]*0.05 print("Replacing all NaN values with 0:") /DF.fitina(O,inplace=True) [print(DB) Sample Output Original DataFrame AP Assam Sikkim TN AUMS GC 17 6.0 NaN 22 7.0 PC 30 NaN 1.0 24 NaN TS 7150 726.0 100.0 46 673.0 Fees 25000 33000.0 27000.0 23000 15000.0 Changing the name from AP to Andhra: Andhra Assam Sikkim TN AIMS ac 17 60 NaN 22 7.0 PC 30 Now 10 24 Naw TS 7150 726.0 100.0 46 673.0 Fees 25000 33000.0 27000.0 23000 15000.0 Counting and displaying non-NaN values of each column: Andhra 4 Assam 3 Sikkim 3 T™ 4 AIMS 3 dtype: inte Counting and displaying non-NoN values of cach row: cc 4 po 3 Ts 5 Fees 5 dtype: intea Increasing the fess of all colleges by 5% Andhra Assam Sikkim TN AIMS Gc 170 60 NaN 220 7.0 Pe 30.0 NaN 1.0 24.0 NaN TS 7150.0 726.0 100.0 46.0 673.0 Fees 26250.0 34650.0 28350.0 24150.0 15750.0 Replacing ali NaN values with 0: Andhra Assam Sikkim TN AIMS ac 17.0 60 0.0 22.0 7.0 PC 30.0 0.0 10 240 0.0 TS 7150.0 726.0 100.0 46.0 673.0 Fees 26250.0 34650.0 28350.0 24150.0 15750.0 To write a Python program to create a panda’s DataFrame called DF for the following table using Dictionary of List and display the details of students whose Percentage is more than 85. =e [Degree [Percentage 31 Ana 30 $2 Arun 3s 33 faa 2 34] charan| tase 76 ‘ss Mano 2 'stu_Name':['Anu', 'Arun','Bala', 'Charan', 'Mano'], 'Degree': ,'MCA','M.E','M.Sc', 'MCA'], 'Percentage':[90,85,91,76,84)} F=pd.DataFrame (D,index=['S1','S2','S3','S4','S5']) print (DF.loc[DF['Percentage']>85]) RESULT: Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT; Stu_Name Degree Percentage sl Anu MBA 90 83 Bala MAE 91 DATE: CREATING A PYTHON PROGRAM TO DISPLAY THE ATTRIBUTES OF A DATAFRAME AIM: To write a Python program to create a DataFrame using Dictionary of list and display the following attributes of the DataFrame: (i) index (ii) columns (iii) axes (iv) dtypes (v) shape (vi) dimension (vii) T import pandas as pd ID=['Stu_Name';['Anu’,'Bal: “i ‘Degree’ MBA','MCA‘,"M.E', M.Sc], ‘Percent's[90,85,91,76), IDF=pd.DataFrame(D,index=['Stu1','Stu2','Stu3','Stu4]}) fladexi'Stut, ‘Stax, ‘Stud, Stas], dtyperobject), Indeni[Stu Name’, Degree’, Percent], dtyper'edject] ta types of the DataFrame ist DATE: ¢ [ON PROG} 1S] oO Ow. WISE AND COLUMN-WISE USING ITERROWS() AND ITERITEMS() AIM: To write a Python program to create a panda’s DataFrame called Students for the following table and demonstrate iterrows and iteritems. SOURCE CODE; import pandas as pd D={"Stu_Name":["Anu", "Arun", "Bala", "Charan", "Mano"), "Degree": ["MBA" , "MCA" ,"¥.E", "M.Sc", "MCA"), "Percentage" : [90,85,91,76,84)) DF=pd.DataFrame (D, index=["S1","S2","83","S4","S5"]) for (row,values) in DF.iterrows(): print (row) print (values) print ()#To print an expty line after each row. for (col,values) in DF.iteritens(): print (col) print (values) print () RESULT: ‘Thus, the above Python program has been executed successfully, and the output has been verified. # Output for Iterrows() # Output for items! si 7 stu Name = & a soe Percentage 90 ae ane Name: S1, dtype: object ores ee s4 Charan 82 85 Mano stu Name Arun Name: Stu_Name, dtype: object Degree McA Percentage es Degree Name: 52, dtype: object sl MBA 82 0 MCA 53 5300 ME stu Name Bala sé M.Sc Degr: ME ss MCA Percentage ot Name: Degree, dtype: object Name: 53, dtype: object Percentage a4 sl 90 Stu_Name Charan =) (gst Degree M.s0 He Percentage 16 aii ae Name: 84, dtype: object 85 84 SS Name: Percentage, dtype: int64 Stu_Name Mano Degree McA Percentage 84 Name: $5, dtype: ebject [Da RICE TER RIDE ICIS TEED TEI SE SRT A CSV FILE AIM: To Write a Python program to store the details of Employess’ such as Empno, Name, Salary into a Employee.csv file. Also, write a code to read employee details from csv file. SOURCE CODE: import pandas as pd Emp={ "Name"; ["Anu", "Ram", "Raj", "Mano", "Rajan"], "Age": [25,27,35,27,321, "State": ("IN", "AB", "IN", "KA", "AB"], "Salary" :[26000,35000, 45000 ,25000,37000]} DF=pd.DataFrame (Emp, index=["E1" "E38", "EA" ,"E5")) DF.to_csv("E:\\Data\\Emp.csv") Data=pd.read_esv("E:\\Data\\Exp.csv") print (Data) RESULT: ‘Thus, the above Python program has been executed successfully, and the output has been verified. SAMPLE OUTPUT: EL Anu 25 TN 26000 0 £2 Ram 27 AP 35000 1 £3 Raj 35 TN 45000 2 E4 Mano 27 KA 25000 3 E5 Rajan 32 AP 37000 To write a Python program to plot a Line chart to depict the changing weekly Onion and Brinjal prices for four weeks. Also, give appropriate axes labels, title and keep marker style as Diamond and marker edge color as ‘red’ for Onion. SOURCE CODE: import matplotiib.pyplot as pit Weeks=[1,2,3,4] lonion=[45,25,32,801 IBrinjal=[16,18,45,50] plt.title ("Price Analysis") plt.xlabel ("Weeks") plt.ylabel ("Prices") lplt.plot (Weeks, Onion,marker='D' ,markersize=15,markeredgecolor='r' ) plt.plot (Weeks, Brinjal) plt..show() RESULT: ‘Thus, the above Python program has been executed and verified successfully, and its respective chart has been generated successfully. SAMPLE OUTPUT: Price Analysis » EX.NO: 18 DATE: AIM; To write a Python program to create a DataFrame for subject-wise average, save it to a CSV file, and then draw a bar chart using Matplotlib with a width of each bar as 0.25, specifying different colors for each bar. Additionally, provide a proper title and axes labels for the bar chart Source Code; [iaport pandas as pa jiaport matplotlib.pyplot as pit [DF= pd.DataFramet{ Subject’: [Eng'yPhy’, ‘Maths’, ‘Che’, 1P},Sub_Avg:: [72,85, 78, 92, 80],inden={ Sub1',Sub2,Sub3Subé'SubS]} [pP.to cav{'D:\\Ciass12\\IP\ \Subjects.csv") IData=pd.rvad_cer{'D:\\Clase}2\ \IP\ \Subjects.csv"] ptt. adabett’Subjects") ptt.ytabell Averaze’) tt title|'Subject Average Analytis}) ptt.bar(Datal Subject] Data Sub Avel,width=0.25,color=[e'sr,e,Dym]} [ptt.show) RESULT: Thus, the above Python program has been executed and verified successfully, and its respective chart has been generated successfully. Sample Output: Subject Average Analysis o swetage 20 9) thy the che . subjects CREATING. ‘HON PROGRAM FOR. iG TIPLI BAR CHART FROM A CSV FILE. AIM: To write a Python program to plot a multiple bar chart From CSV file using Matplotlib for subject wise Scores of Class A, Class B, and Class C. Different colors represent each class, and subjects include English,Accountancy,Economics,BST and IP. Proper labels, a title and a legend are displayed on the chart. Source Code: import pandas as pd import numpy as np import matplotlib.pyplot as pit laata = { “Subject [Eng’, ‘Acc’, ‘Eco’, ‘BST’, IP], "ClassA': [85, 78, 92, 80,98), ‘ClassB': [90, 65, 88, 75,87], 'ClassC’s [75, 82, 60, 90,94]} IDF=pd.DataFrame(data) IDF.to_esv("D:\ \CLASS12\ \IP\\Class.csv") Data=pd.read_csv{"D:\\CLASS12\ \IP\\Class.csv") pit.xtabel’Subject=) pit.ytaboy Average’) pit.titte( Subject-wise Average for Classes A, B, and C') |x=np.arange(5) pit.bax(DF[ Subject ],DFI'ClassA'],width=0.15 Jabel='Class-A') pit.bar{n+0.15,DF[ ClassB'],width=0.15,label="Class-B") pit.bar(e+0.30,DF[ CiaseC ],width=0.15,1ab pitdegend() pit.show() RESULT: Thus, the above Python program has been executed and verified successfully, and its respective chart has been generated successfully. Sample Output: Subiectwine Average for Classes A,B, ance rr sles DATE: CREATING A PYTHON PROGRAM FOR PLOTTING PLOTTING HISTOGRAM AIM: ‘To write a Python program to plot a Histogram for the following class interval or range. Also, give appropriate axes name, title and edege color as ‘red’. import matplotlib.pyplot as plt Marks=[40,,60,55,20,35,70, 60,89, 20,33] plt.title("Maths Marks-Histogran of class XII") jplt.xlabel ("Mark Ranges") Jplt.ylabel ("No.of Students") jplt.hist (Marks ,bins=[0,33,45, 60,100] ,edgecolor='red' Iplt.show() RESULT: Thus, the above Python program has been executed and verified successfully, and the respective chart has been generated successfully. SAMPLE OUTPUT: Maths Marks Histogram of cass a AIM: To write Queries for the following Questions based on the given table: EmpID| Name | Gender | Age Dept DOJ Salary City 1 Praveen | M 25 | Sales 1989-06-08 | 20000 | Chennai 2 Arun M 29 | Marketing | 1989-09-26 | 22000 | Chennai 3 Usha | F 27 | Finance [1994-08-09 [ 25000 | Bangalore 4 Bala M 31_| Sales 1990-03-23 | 27000 | NULL 5 Rani F 28 _| Marketing | 1990-04-23 | 27000 | Mumbai 6 Nisha__| F 26 | NULL 1991-02-24 | 18000 | Bangalore 7 Manoj_| M 32_| Finance 1982-05-06 _| 30000 | Goa (a) Write a Query to Create a new database in the name of "EMPS". CREATE DATABASE EMPS; (b) Write a Query to Open the database EMPS. USE EMPS; (c) Write a Query to create the above table called: Info CREATE TABLE INFO (EmpID int primary key, Name varchar(15), Gender varchar(3),Age int,Dept varchar{15),DOJ date, Salary int, City varchar{10)}; (d) Write a Query to list all the existing database names. SHOW DATABASES; (e) Write a Query to List all the tables that exists in the current database. SHOW TABLES; Output: (f) Write a Query to insert all the rows of above table into Info table INSERT INTO INFO VALUES (1,'Praveen','M’, 25,'Sales','1989-06-08',’20000','Chennai’); INSERT INTO INFO VALUES(2,’Arun’,'M’,29,'Marketing’,'1989-09-26',22000, INSERT INTO INFO VALUES(3,'Usha’,'F',27,'Finance’,'1994-08-09',25000, Bangalore’); \SERT INTO INFO VALUES(4,'Bala’,'M',31,'Sales','1990-03-23',27000,NULL); INSERT INTO INFO VALUES(5,'Rani’,F’,28,'Marketing’,'1990-04-23',27000,'Mumbai’); INSERT INTO INFO VALUES (6,'Nisha’,'F', 26, NULL,'1991-02-24', 18000, 'Bangalore/); INSERT INTO INFO VALUES (7,'Manoj','M’, 32,'Finance’,'1982-05-06', 30000,'Goa’); (g) Write a Query to display all the details of the Employees from the above table 'INFO'. SELECT * FROM INFO; Output: Gender | Age | Dept Se a eed cry erect econ or Mere ees ry ecu 1994-08-09 | 25000 Praveen | jl ! aa | i pala | eC eC eee me | i | | | | eos Reni eee ee ee uy ae pa Paras PCa Manoj pLt oe Coy Ei Tr) Paucar Ex.Noi 22 AIM: SQIL COMMANDS EXERCISE - 2 {Basic Queries = Il) To write Queries for the following Questions based on the given table: EmpID| Name |Gender|Age| Dept DOJ Salary | City 1 Praveen | M 25 | Sales 1989-06-08 | 20000 | Chennai 2 Arun [M 29_| Marketing | 1989-09-26 | 22000 | Chennai 3 Usha |F 27_| Finance | 1994-08-09 | 25000 | Bangalore 4 Bala |M 31_| Sales 1990-03-23 | 27000 | NULL 5 Rani__|F 28_| Marketing | 1990-04-23 | 27000 | Mumbai 6 Nisha__| F 26_| NULL 1991-02-24 | 18000 | Bangalore 7 Manoj_|M 32 _| Finance | 1982-05-06 | 30000 | Goa (a) Write a Query to Display Employees’ name and City from the above table. SELECT NAME, CITY FROM INFO; Praveen | Chennai ru araees Usha Et) co rey rears) (b) Write a Query to Display all details of Employees who are living in Chennai. SELECT * FROM INFO WHERE CITY='CHENNAI'; Output: (c} Write a Query to get the name and salary of the employee whose salary is above 15000 and gender is not male. SELECT NAME,SALARY FROM INFO WHERE SALARY >15000 AND GENDER<>'M'; = eC Cr ee Cra eee De esa (d) Write a query to update increase 10% Salary of an employee whose City is 'CHENNAT and Gender is ’MALE’. UPDATE INFO SET SALARY=SALARY+ (SALARY*0.10) WHERE CITY='CHENNAI AND GENDER="MALE’; Output (After Updating): era UY r Tei’ cr Ea ad | salary | ae ror) fey Povey pen ees eC CecE ses sr ae Crees | free | | Fr eee ees | | | | i i Chennai | | Pees coal ees i | 27@¢0 | Mumbai | | | | | Rani Dreiry Peis Marketing | 1990-04-2 rae poe Tne? Finance | 1982-05-06 18200 | Bangalore rd | | | Bala i | i DATE: SQL COMMANDS EXERCISE - 3 {Aggregate Functions, Order By Group By, Havning Clause} AIM: To write Queries for the following Questions based on the given table: EmpID| Name | Gender] Age| Dept Dos Salary | City 1 Praveen | M 25 | Sales 1989-06-08 | 20000 | Chennai 2 Arun M 29 | Marketing | 1989-09-26 | 22000 | Chennai 3 Usha | F 27 | Finance [1994-08-09 [ 25000 | Bangalore 4 Bala _|M 31 | Sales 1990-03-23 | 27000 | NULL 5 Rani F 28 _| Marketing | 1990-04-23 | 27000_| Mumbai 6 Nisha__| F 26 | NULL 1991-02-24 | 18000 | Bangalore 7 Manoj__| M 32_| Finance 1982-05-06 _| 30000 _| Goa (a) Write a Query to list names of Employees in Descencling order. SELECT NAME FROM INFO ORDER BY NAME DESC; (b) Write a Query to find a total salary of all employees. SELECT SUM(SALARY) FROM INFO; {c) Write a Query to display maximum salary and minimum salary of employees. SELECT MAX(SALARY), MIN(SALARY) FROM INFO; (a) Write a Query to count the number of employees earning more than 25000. SELECT COUNT(SALARY) FROM INFO WHERE SALARY>25000; (e) Write a query to display sum of salary of the employees grouped by department wise SELECT DEPT, SUM(SALARY) FROM INFO GROUP BY DEPT; Eset) 53620 Berd () Write a query to display the department names where number of employees are greater than or equal to 2. SELECT DEPT FROM INFO GROUP BY DEPT HAVING COUNT(*)>=2; | Sales ccs Ua | Finance | oe E Ex.No: 24 DATE: ‘SQL COMMANDS EXERCISE - 4 {Mathemat! ons) AIM: ‘To write Queries for the following Questions based on the given table -"STU": ANKIT cy ct CHARAN | N Traad aaa eaneNg Pa io eer thre Bees i | uy HINDI | | i cd (a) Write a Query to Display square of age that got admission in the month of August. SELECT POWER(AGE,2) FROM STU WHERE DOA LIKE '%-08-%'; + aac ar | (b) Write 2 Query to display Remainder of column Percentage divide by 3. SELECT MOD(MARKS,3) FROM STU; Output: ° ea Brees Pr IetrrEy Sty om epee. " “sty KUUND(PERCENTAGE,0) FROM STU, Output; ocr a cr (4) Display Name, Percentage and round up the remainder marks up to 2 decimal places. SELECT NAME, ROUND(MOD|PERCENTAGE,3),2) FROM STU; Output: Ate Cream I | vi ae arn HHO iii AE oi atiiienienne Co pty nary SUT ya Fee) real ctr ay cele ase CNY TC rey oan ag PCL Ares Pitas ese eared Poa aa SLT bray Lepsae nen gen a (a) Write a Query to display Department name in lower case letters. SELECT LCASE(DEPT) FROM STU; ip Lute Ey PSUs ieny (b) Write a Query to display department name and its respective number of characters in Dept column. SELECT DEPT,LENGTH(DEPT) FROM STU; erence Perea Fs i peg Corie] i | 1 i i} {c) Write a Query to display first 2 characters of the column Name. SELECT LEFT(NAME,2) FROM STU; (d) Write a Query to display first 2 characters of the column Name. SELECT RIGHT(NAME,2) FROM STU; {e) Write a query to display the names of all students and extract five characters from the third position of the ‘Name field. SELECT SUBSTR(NAME,3,5) FROM STU; SQL COMMANDS EXERCISE - 6 (Date Functions} To write Queries for the following Questions based on the given table: os - Seema os Rollno Gender | AGE | DEPT a3 cc raya Bt HINDT reg cs {a) Write a Query to display student name and month of date of admission of all students. SELECT NAME, MONTH(DOA) FROM STU; ere) (b) Write a Query to display Student name and day name of the students’ DOA of the table STU. SELECT NAME, DAYNAME(DOA) FROM STU; Output: | NAME — | DAVNAME(DOA) | a - Ere etd ANKIT | Wednesday ‘ANU | Friday BALA | Thursday CHARAN | Friday at Std DINESH | Sunday {c) Write a query to display the Joining year of IP students. SELECT YEAR(DOA) FROM STU WHERE DEPT=' (d) Write a Query to Display the month for the date_of_birth of all students. SELECT NAME, MONTHNAME(DOA)FROM STU; ut: NAME — | MONTHNAHE(DOA) i | January | eu | oly | | July | Cer | cera i Pyro met ts I (e) Write a query to display the names of the students who joined in the month of June. SELECT NAME FROM STU WHERE MONTHNAME(DOA)='June'; Output: School or CBSE Logo CENTRAL BOARD OF SECONDARY EDUCATION School Name Address A PRACTICAL RECORD FILE IS SUBMITTED TO DEPARTMENT OF INFORMATICS PRACTICES FOR ‘THE PARTIAL FULLFILLMENT OF AISSCE EXAMINATION SESSION -__ SUBMITTED BY: [NAME OF STUDENT] HOD(COMPUTER):[NAME OF SUBJECT TEACHER] CLASS: [CLASS] ROLL NO: [XXXXXXX] ACKNOWLEDGEMENT I wish to express my deep sense of gratitude and indebtedness to our learned teacher TEACHER’S NAME , PGT COMPUTER SCIENCE, [SCHOOL NAME] for his invaluable help, advice and guidance in the preparation of this project. I am also greatly indebted to our principal [Name of principal] and school authorities for providing me with the facilities and _ requisite laboratory conditions for making this practical file. I also extend my thanks to a number of teachers ,my classmates and friends who helped me to comonlete this nractical file successfulhi. CERTIFICATE This is to certify that [Name of Student] , student of Class XII, [NAME OF SCHOOL] has completed the PRACTICAL FILE during the academic year [SESSION] towards partial fulfillment of credit for the Informatics Practices practical evaluation of SSCE-20__ and submitted satisfactory report, as compiled in the following pages, under my supervision, Total number of practical certified are : 20. Internal Examiner External Examiner Signature Signature

You might also like