SQL 2018 Practical Removed Down
SQL 2018 Practical Removed Down
c) select movie_id, moviename, productioncost from movie where productioncost >150000 and
productioncost <1000000;
d.) select movieid, moviename, productioncost + businesscost "total earning" from movie;
19. Command for using group by and having clause with whereclause.
Suppose your school management has decided to conduct cricket matches between students of Class XI
and Class XII. Students of each class are asked to join any one of the four teams – Team Titan, Team
Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be
conducted between these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
c. It should have a column TeamID for storing an integer value between 1 to 9, which refers to
unique identification of a team.
d. Each TeamID should have its associated name (TeamName), which should be a string of
length not less than 10 characters.
e. Using table level constraint, make TeamID as the primary key.
f) Show the structure of the table TEAM using a SQL statement.
g) As per the preferences of the students four teams were formed as given below. Insert these
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.
MatchID MatchDate FirstTeamID SecondTeamID FirstTeamScore SecondTeamScore
M1 2021/12/20 1 2 107 93
M2 2021/12/21 3 4 156 158
M3 2021/12/22 1 3 86 81
M4 2021/12/23 2 4 65 67
M5 2021/12/24 1 4 52 88
M6 2021/12/25 2 3 97 68
c) desc team;
d) Inserting data:
mqsql> insert into team -> values(1,'Tehlka');
mqsql> insert into team -> values(2,'Toofan');
mqsql> insert into team -> values(3,'Aandhi');
mqsql> insert into team -> values(4,'shailab');
b) Selectmatch_details.matchid,match_details.firstteamid,team.teamname,match_details.firstteamsco
re from match_details, team where match_details.firstteamid = team.teamid and
match_details.firstteamscore>70;
import mysql.connector as ms
db=ms.connect(host="localhost",user="root",passwd="root",database='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 stop entry:")
if ch in 'Nn':
break
except Exception as e:
print("Error", e)
def update_rec():
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_rec():
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. Delete Record\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:
break
else:
print("Wrong option selected")
OUTPUT