0% found this document useful (0 votes)
288 views

Practicals File 2025

Practical file class12 computer 1

Uploaded by

anishrawat8021
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)
288 views

Practicals File 2025

Practical file class12 computer 1

Uploaded by

anishrawat8021
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/ 19

SQL QUERIES

1. C ONSIDER THE FOLLOWING MOVIE TABLE AND WRIT E THE SQL QUERIES BASED O N I T .

Movie_ID MoveName Type ReleaseDate ProductionC BusinessCo


ost st
M001 The kashmir files Action 2022/01/26 1245000 1300000
M002 Attack Action 2022/01/28 1120000 1250000
M003 Looop Lapeta Thriller 2022/02/01 250000 300000
M004 Badhai Do Drama 2022/02/04 720000 68000
M005 Shabaash Mithu Biography 2022/02/04 1000000 800000
M006 Gehraiyaan Romance 2022/02/11 150000 120000
a) Display all information from movie.
b) Display the type of movies.
c) Display movieid, moviename, total_eraning by showing the business done by the
movies. Claculate the business done by movie using the sum of productioncost and
businesscost.
d) Display movieid, moviename and productioncost for all movies with
productioncost greater thatn 150000 and less than 1000000.
e) Display the movie of type action and romance.
f) D ISPLAY THE LIST OF MOVIES WHICH ARE GOING TO RELEASE IN F EBRUARY , 2022.
Answers:
a) select * from movie;
b) select distinct from a movie;

c) select movieid, moviename, productioncost + businesscost"total earning" from


movie;

d) select movie_id,moviename, productioncost from moviewhere productcost


is >150000 and <1000000;

e) select moviename from movie where type ='action' ortype='romance';

f) select moviename from movie where month(releasedate)=2;


2.W RITE FOLLOWING QUERI ES :
a) Write a query to display cube of 5.
b) Write a query to display the number 563.854741 rounding off to the next hnudred.
c) Write a query to display "put" from the word "Computer".
d) Write a query to display today's date into DD.MM.YYYY format.
e) Write a query to display 'DIA' from the word "MEDIA".
f) Write a query to display moviename - type from the table movie.
g) Write a query to display first four digits of productioncost.
h) Write a query to display last four digits of businesscost.
i) Write a query to display weekday of release dates.
j) Write a query to display dayname on which movies are going to be released.

Answers:
a) select pow(5,3);

b) select round(563.854741,-2);

c) SELECT MID (“C OMPUTER ”,4,3);


d) select concat(day(now()), concat('.',month(now()),concat('.',year(now()))))
"Date";

e)select right("Media",3);

f)select concat(moviename,concat(' - ',type)) from movie;

g)select left(productioncost,4) from movie;

h)select right (businesscost,4)from movie;


i)select weekday(releasedate) from movie;

j)select dayname(releasedate) from movie;

3. S UPPOSE
Y OUR SCHOOL M ANAGEMENT HAS DECI DE D TO CONDUC T CRICKET MATCHES
BETWEEN STUDEN TS OF C LASS XI AND C LASS XII. S TUDENTS OF EACH CLASS ARE
ASKED TO JOI N ANY ON E OF THE FOUR T EAMS – T EAM T ITAN , T EAM R OCKERS , T EAM
M AGNET AND T EAM H URRICANE . D URING SUMMER VACATIONS , VARIOUS MATCHES
WILL BE CO NDUCT ED BET WEEN THESE T EAMS . H ELP YOUR SPORTS TEACHER TO DO
THE FOLLOWING :
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
a. It should have a column TeamID for storing an integer value between 1 to
9,which refers to unique identification of a team.
b. Each TeamID should have its associated name (TeamName), which should be a
string of length not less than 10 characters.
c. Using table level constraint, make TeamID as the primary key.
c) Show the structure of the table TEAM using a SQL statement.
d) As per the preferences of the students four teams were formed as given below.
Insertthese four rows in TEAM table:
a. Row 1: (1, Tehlka)
b. Row 2: (2, Toofan)
c. Row 3: (3, Aandhi)
d. Row 3: (4, Shailab)
e) Show the contents of the table TEAM using a DML statement.
f) Now create another table MATCH_DETAILS and insert data as shown below. Choose
appropriate data types and constraints for each attribute.
MatchI MatchDa FirstTeam SecondTea FirstTeamSc SecondTeamS
D te ID mID ore core

M1 2021/12/ 2 107 93
20

M2 2021/12/ 4 156 158


21

M3 2021/12/ 3 86 81
22

M4 2021/12/ 4 65 67
23

M5 2021/12/ 4 52 88
24

M6 2021/12/ 3 97 68
25

A NSWERS :

a) create database sports;

b) Creating table with the given specification

create table team -> (teamid int(1), -> teamnamevarchar(10), primary key(teamid));

c) desc team;
I NSERTING DATA :
mqsql> insert into team -> values(1,'Tehlka');

S HOW THE CONTENT OF TABLE - T EAM :


SELECT * FROM TEAM ;

C REATING ANOTHER TABLE :


create table match_details
-> (matchid varchar(2) primary key,
-> matchdate date,
-> firstteamid int(1) references team(teamid),
-> secondteamid int(1) references team(teamid),
-> firstteamscore int(3),
-> secondteamscore int(3));
4. Write following queries:
a) Display the matchid, teamid, teamscore whoscored more than 70 in first ining
along with team name.
b) Display matchid, teamname and secondteamscore between 100 to 160.
c) Display matchid, teamnames along with matchdates.
d) Display unique team names
e) Display matchid and matchdate played by Anadhi and Shailab.
A NSWERS :
a) select match_details.matchid, match_details.firstteamid,
team.teamname,match_details.firstteamscore from match_details, team where
match_details.firstteamid = team.teamid and match_details.first

b) selectmatch_details.matchid,match_details.firstteamid,team.teamname,match_d
etails.firstteamscore from match_details, team where match_details.firstteamid=
team.teamid and match_details.firstteamscore>70;
c) mselect matchid, teamname, firstteamid, secondteamid,matchdate from
match_details, team where match_details.firstteamid = team.teamid;

d) select distinct(teamname) from match_details, team where


match_details.firstteamid = team.teamid;

e)select matchid,matchdate from match_details, team where match_details.firstteamid =


team.teamid and team.teamname in ('Aandhi','Shailab');
5. Consider the following table and write the queries:

itemno item dcode qty unitprice stockdate

S005 Ballpen 102 100 10 2018/04/22

S003 Gel Pen 101 150 15 2018/03/18

S002 Pencil 102 125 2018/02/25

S006 Eraser 101 200 2018/01/12

S001 Sharpner 103 210 2018/06/11

S004 Compass 102 60 35 2018/05/10

S009 A4 Papers 102 160 2018/07/17

a) Display all the items in the ascending order of stockdate.


b) Display maximum price of items for each dealer individually as per dcode from stock.
c) Display all the items in descending orders of itemnames.
d) Display average price of items for each dealer individually as per doce from stock
which avergae price is more than 5.
e) Diisplay the sum of quantity for each dcode.
A NSWERS :
a) select * from stock order by stockdate;

b) S ELECT DCODE , MAX ( U NITPRICE ) FROM STOCK GROUP BY CODE ;


c) select * from stock order by item desc;

d) select dcode,avg(unitprice) from stock group by dcodehaving


avg(unitprice)>5;

e) select dcode,sum(qty) from stock group by dcode;


PYTHON DATABASE CONNECTIVITY
1. Write a MySQL connectivity program in Python to
 Create a database school
 Create a table students with the specifications - ROLLNO integer, STNAME
character(10) in MySQL and perform the following operations:
o Insert two records in it
o Display the contents of the table
2. Perform all the operations with reference to table ‘students’ through MySQL-
Pythonconnectivity.
A NSWERS :
1. Using pymysql - Code:
import pymysql as ms
#Function to create Database as per users choicedef c_database():
try:
dn=input("Enter Database Name=") c.execute("create database
{}".format(dn))c.execute("use {}".format(dn)) print("Database
created successfully")
except Exception as a: print("Database
Error",a)
#Function to Drop Database as per users choicedef d_database():
try:
dn=input("Enter Database Name to be dropped=")c.execute("drop database
{}".format(dn)) print("Database deleted sucessfully")
except Exception as a: print("Database Drop
Error",a)

#Function to create Tabledef


c_table():
try:
c.execute('''create table students(
rollno int(3), stname
varchar(20)
); ''')
print("Table created successfully")except Exception as
a:

PRINT ("C REAT E T ABL E E RROR ", A )


#Function to Insert Data

def e_data():try:

while True:
rno=int(input("Enter student rollno="))name=input("Enter
student name=") c.execute("use {}".format('school'))
c.execute("insert into students
values({},'{}');".format(rno,name)) db.commit()
choice=input("Do you want to add more record<y/n>=")if choice in "Nn":
break

except Exception as a: print("Insert Record Error",a)

#Function to Display Datadef


d_data():
try:
c.execute("select * from students")data=c.fetchall()
for i in data:print(i)
except Exception as a: print("Display Record
Error",a)

db=ms.connect(host="localhost",user="root",password="root") c=db.cursor()
while True:
print("MENU\n1. Create Database\n2. Drop Database \n3.
Create Table\n4. Insert Record \n5. Display Entire Data\n6.Exit")
choice=int(input("Enter your choice<1-6>="))if choice==1:
c_database()elif
choice==2:
d_database()elif
choice==3:
c_table() elif
choice==4:
e_data() elif
choice==5:
d_data() elif
choice==6:
break
else:
print(“Wrong option selected:”)
2. using mysqlconnector
import mysql.connector as ms db=ms.connect(host="localhost",user="root",passwd="root",datab
ase='school')
cn=db.cursor() def
insert_rec():
try:
while True:
rn=int(input("Enter roll number:"))sname=input("Enter
name:") marks=float(input("Enter marks:"))
gr=input("Enter grade:") cn.execute("insert into students
values({},'{}',{},'{}')".format(rn,sname,marks,gr)) db.commit()
ch=input("Want more records? Press (N/n) to stopentry:")
if ch in 'Nn':break
except Exception as e:
print("Error", e)
def
update_r
ec():try:
rn=int(input("Enter rollno to update:"))marks=float(input("Enter new
marks:")) gr=input("Enter Grade:")
cn.execute("update students set marks={},grade='{}'where
rno={}".format(marks,gr,rn))
db.commit() except
Exception as e:
print("Error",e)
def
delete_r
ec():try:
rn=int(input("Enter rollno to delete:"))cn.execute("delete from students
where
rno={}".format(rn))
db.commit() except
Exception as e:
print("Error",e)
def view_rec():try:
cn.execute("select * from students")
except Exception as e:
print("Error",e)
while True:
print("MENU\n1. Insert Record\n2. Update Record \n3. DeleteRecord\n4. Display Record
\n5. Exit")
ch=int(input("Enter your choice<1-4>="))if ch==1:
insert_rec()elif
ch==2:
update_rec()elif
ch==3:
delete_rec()elif
ch==4:
view_rec()elif
ch==5:
breakelse:
print("Wrong option selected")
O UTPUT :

You might also like