CREATE TABLE Item (
ItemName VARCHAR(50),
Category VARCHAR(30),
Price DECIMAL(10,2),
StockQty INT
);
CREATE TABLE Item (
Create the below tables and perform the required queries:
FURNITURE:
+----+-----------------+--------------+-------------+----------+----------+
| no | itemname | type | dateofstock | price | discount |
+----+-----------------+--------------+-------------+----------+----------+
| 1 | dolphin | baby cot | 19-02-2002 | 9500.00 | 20 |
| 2 | decent | office table | 01-01-2002 | 25000.00 | 30 |
| 3 | comfort zone | double bed | 12-01-2002 | 25000.00 | 25 |
| 4 | donald | baby cot | 24-02-2002 | 6500.00 | 15 |
| 5 | royal finish | office table | 20-02-2002 | 18000.00 | 90 |
| 6 | royal tiger | sofa | 22-02-2002 | 31000.00 | 30 |
| 7 | economy sitting | sofa | 13-12-2001 | 9500.00 | 25 |
| 8 | eating paradise | dining table | 19-02-2002 | 11500.00 | 25 |
+----+-----------------+--------------+-------------+----------+----------+
ARRIVALS:
+----+--------------+------------+-------------+----------+----------+
| no | itemname | type | dateofstock | price | discount |
+----+--------------+------------+-------------+----------+----------+
| 1 | wood comfort | double bed | 23-03-2003 | 25000.00 | 25 |
| 2 | old fox | sofa | 20-03-2003 | 17000.00 | 20 |
| 3 | micky | baby cot | 1-4-2003 | 7500.00 | 15 |
+----+--------------+------------+-------------+----------+----------+
CREATE STATEMENTS :
CREATE DATABASE lab16;
USE lab16;
create table furniture(
no int primary key,
itemname varchar(50) not null,
type varchar(50) not null,
dateofstock date not null,
price decimal(8,2),
discount numeric(2)
);
create table arrivals(
no int primary key ,
itemname varchar(50) not null,
type varchar(50) not null,
dateofstock date not null,
price decimal(8,2) not null,
discount numeric(2)
);
insert into furniture values
(1,'dolphin','baby cot','2002-02-19',9500.00,20),
(2,'decent','office table','2002-01-01',25000.00,30),
(3,'comfort zone','double bed','2002-01-12',25000.00,25),
(4,'donald','baby cot','2002-02-24',6500.00,15),
(5,'royal finish','office table','2002-02-20',18000.00,90),
(6,'royal tiger','sofa','2002-02-22',31000.00,30),
(7,'economy sitting','sofa','2001-12-13',9500.00,25),
(8,'eating paradise','dining table','2002-02-19',11500.00,25);
insert into arrivals values
(1,'wood comfort','double bed','2003-03-23',25000.00,25),
(2,'old fox','sofa','2003-03-20',17000.00,20),
(3,'micky','baby cot','2003-4-1',7500.00,15);
QUERIES
i)List itemnames and types of those items which were stocked in February from the furniture table in descending order of the item name
ii)Display item name and date of stock of those items in which the discount percentage is less than 20 or more than 25.
v)Display furniture items having a price greater than the average price of all arrivals.
vii) Display item no, item name, mrp and the discounted price for all items
viii)Move all the rows from arrivals into the furniture table
Create the below tables :
Create the below tables :
DEPARTMENT :
PRACTICE :
CREATE TABLE STREAM (
s_id INT PRIMARY KEY,
s_name VARCHAR(20)
);
CREATE TABLE STUDENT (
adno INT PRIMARY KEY,
fname VARCHAR(20),
lname VARCHAR(20),
class VARCHAR(5),
sec CHAR(1),
fee INT,
mobile BIGINT,
area VARCHAR(30),
s_id INT,
FOREIGN KEY (s_id) REFERENCES STREAM(s_id)
);
Create the below tables :
DEPARTMENT :
CREATE TABLE department (
DeptName VARCHAR(20) PRIMARY KEY,
HOD VARCHAR(30),
RoomNo VARCHAR(10),
Budget NUMERIC(7)
);
INSERT INTO department VALUES
('Computer', 'Dr. Sen', 'C101', 500000),
('History', 'Dr. Malhotra', 'H202', 300000),
('Math', 'Dr. Iyer', 'M303', 400000);
CREATE TABLE teacher (
No INT PRIMARY KEY ,
Name VARCHAR(20) NOT NULL,
Age NUMERIC(2) CHECK (Age BETWEEN 20 AND 70),
Department VARCHAR(20),
DOJ DATE,
Salary FLOAT,
Sex VARCHAR(1) CHECK (Sex IN ('M', 'F')),
FOREIGN KEY (Department) REFERENCES department(DeptName)
);
INSERT INTO teacher VALUES
(111,'Jugal', 34, 'Computer', '1997-01-10', 12000, 'M'),
(222,'Sharmila', 31, 'History', '1998-03-24', 20000, 'F'),
(333,'Sandeep', 32, 'Math', '1996-12-12', 30000, 'M'),
(444,'Sangeeta', 35, 'History', '1999-07-01', 40000, 'F'),
(555,'Rakesh', 42, 'Math', '1997-09-05', 25000, 'M'),
(666,'Shyam', 50, NULL, '1998-06-27', 30000, 'M'),
(777,'Shiv Om', 44, 'Computer', '1997-02-25', 21000, 'M'),
(888,'Shalaka', 33, 'Math', '1997-07-31', 20000, 'F');
PRACTICE :
List all teacher names and their departments.
select name,department from teacher;
Display all female teachers.
Select name from teacher where sex='f';
Find teachers who joined before 1998.
Select * from teacher where doj < '1998-01-01';
Show names of teachers with salary above 25,000.
select name,salary from teacher where salary>25000;
List all teachers who do not have a department.
select * from teacher where department is null;
Display the non computer teachers.
select * from teacher where department != 'computer' or department is NULL;
Display the Count of all teachers teachers.
select count(name) as TeacherCount from teacher;
Display the total salary of all teachers.
select sum(Salary) as TotalSalary from teacher;
Display the maximum age among the teachers.
select max(age) as MaxAge from teacher;
Display the earliest DOJ.
select min(doj) as EARLIESTDOJ from teacher;
Display teachers sorted by salary in descending order.
select * from teacher order by salary desc;
List teacher names and their ages who are above 40.
select name,age from teacher where age>40;
Find the average salary of all teachers.
select avg(salary) as AVERAGE_SALARY from teacher ;
Find the average salary of all male teachers.
select avg(salary) from teacher where sex='m';
Find the youngest teacher.
select * from teacher order by age limit 1;
select * from teacher where age = (select min(age) from teacher);
Find the teacher with the maximum salary.
select * from teacher where salary = (select max(salary) from teacher);
List all departments and their HODs.
select deptname,hod from department;
Display departments with a budget over ?4,00,000.
select * from department where budget>400000;
Show department names and room numbers.
select deptname,roomno from department
Find the department with the lowest budget.
select deptname,budget from department
where budget= (select min(budget) from department);
Display the total budget of all departments.
select sum(budget) from department;
List departments in alphabetical order.
select deptname from department order by deptname;
List names that start with s
select name from teacher where name like 's%';
List names that contain and a or an e
select name from teacher where name like '%a%' or '%e%';
List names that contain an a and an e
select name from teacher where name like '%a%' and '%e%';
List names that contain 2 a's
select name from teacher where name like '%a%a%';
List names that contain 'sh' in their name
select name from teacher where name like '%sh%';
List names that have 3rd letter as 'a'
select name from teacher where name like '__a%';
List names that have exactly one letter as 'a'
select name from teacher where name like '%a%' and name not like '%a%a%' ;
List the 8 letter names that end with a.
select name from teacher where name like '_ _ _ _ _ _ _ a';
Display the average salary of teacher :
select avg(salary) from teacher;
Display the department name and the corresponding average salaries:
select department,avg(salary) from teacher group by department;
Display the non-null department name and the corresponding average salaries:
select department,avg(salary)
from teacher
where department is not null
group by department;
Display the non-null department name and the corresponding average salaries, in increasing order of their average salaries.
select department,avg(salary) as AvgSal
from teacher
where department is not null
group by department
order by avgsal;
Display the average salary per sex, in descending order of the average salary
select sex, avg(salary)
from teacher
group by sex
order by avg(salary) desc;
'''A stack named StuStack contains records of students.Each record is represented as a list,eg [101, 'Ravi', 87.5]
Write the following user-defined functions :
(i) pushStu(StuStack,StuList):
this takes StuStack and a list of students as arguments, and pushes the list into the stack.
(ii) popStu(StuStack):
This function pops the topmost student record from the stack and returns it. If empty, display the message
"Stack Underflow" and return None.
(iii) display(StuStack):
This function should display the student by popping it one by one. Also display the record with the highest marks. If the stack is empty, display "No student records".
'''
StuStack=[]
def menu():
while True:
ch=int(input("""MENU :
1.PUSH
2.POP
3.DISPLAY
4.EXIT"""))
if ch==1:
StuList=[]
n=int(input("Enter no of records you want to add : "))
for i in range(n):
stuid=int(input('Enter student id : '))
name=input("Enter name : ")
marks=float(input('Enter marks : '))
l=[stuid,name,marks]
StuList.append(l)
pushStu(StuStack,StuList)
elif ch==2:
rec=popStu(StuStack)
if rec:
print(rec)
else:
print('Empty')
elif ch==3:
display(StuStack)
else:
break
def pushStu(StuStack,StuList):
for i in StuList:
StuStack.append(i)
def popStu(StuStack):
if len(StuStack)>0:
return StuStack.pop()
else:
print('STACK UNDERFLOW')
return None
def display(StuStack):
maxx=0
if len(StuStack)==0:
print('Empty Stack')
return
while StuStack:
rec = StuStack.pop()
print(rec)
if rec[2]>maxx:
maxx=rec[2]
Student=rec
print('Student with maximum marks : ',Student)
menu()
'''GRADE 12: PRACTICAL 12
Create a list Library to implement a STACK data structure
in Python. The Library stack can hold a maximum of 5 records,
each representing a book. Each book is represented as :
{"BookID": <int>, "Title": <str>,
"Author": <str>,"Year": <str>}
Write a menu-driven program to perform :
a) push- Add a new book record to the stack.
b) pop- Delete the topmost book record from the stack.
c) display - To display all book records
d) peek- To view the topmost record of the stack
Handle Underflow and Overflow conditions for the stack .
'''
Library=[]
limit=5
def menu():
while True:
ch=int(input("""MENU:
1.PUSH
2.POP
3.DISPLAY
4.PEEK
5.EXIT
"""))
if ch==1:
bid=int(input("Enter book id "))
title=input("enter title")
auth=input("Enter author")
year=input("Enter year")
book={"BookID":bid, "Title":title,
"Author":auth,"Year":year}
push(Library,book)
elif ch==2:
book=pop(Library)
if book:
print('Popped record : ',book)
elif ch==3:
display(Library)
elif ch==4:
book=peek(Library)
if book:
print('Peekeed record : ',book)
else:
break
def push(Library,book):
if len(Library)<limit:
Library.append(book)
print('Pushed record : ',book)
else:
print('OVERFLOW')
def pop(Library):
if len(Library)>0:
return Library.pop()
else:
print('UNDERFLOW')
return None
def display(Library):
print('Contents of Library')
if len(Library)>0:
for i in Library[::-1]:
print(i)
else:
print('EMPTY')
def peek(Library):
if Library:
return Library[-1]
else:
print('UNDERFLOW')
return None
menu()
"""WAPP to demonstrate the following optionsby creating different methods using binary files for a hospital management application :
(i) adding records of the structure : {'pid':<str>,'pname':<str>,'diag':<str>,'fees':<int>}
(ii)reading and displaying all the records in a
tabular format
(iii)searching and displaying patients who have 'corona'
(iv)update the diagnosis of the given patient id
(Display appropriate messages if patient not found or file not found.)
"""
''' Write a menu-driven program to perform the following
functions on a csv file ‘Cricket.csv’
i) Accept details of n players and write into the file.
The header will be: [Player ID, Player Name, Team, Runs Scored]
ii) Display the id, names and runs of all players who have scored
century. Also display the average of such players.
iii) Search for a player by name and display their details
if found, else show "Player not found."
iv) Update the runs scored by a player (given their Player ID)
If found, ask for new runs and update the file.
'''
import csv
def menu():
while True :
ch=int(input("""MENU :
1.Accept
2.Display
3.Search
4.Update
5.Exit
"""))
if ch==1:
accept()
elif ch==2:
display()
elif ch==3:
search()
elif ch==4:
update()
else:
break
def accept():
n=int(input("Enter no of records : "))
with open("cricket.csv","a",newline="") as f:
writer=csv.writer(f)
if f.tell()==0:
writer.writerow(['Player ID', 'Player Name',' Team', 'Runs Scored'])
for i in range(n):
pid = input("Enter Player ID: ")
name = input("Enter Player Name: ")
team = input("Enter Team Name: ")
runs = int(input("Enter Runs Scored: "))
writer.writerow([pid, name, team, runs])
def display():
with open("cricket.csv","r")as f:
reader = csv.reader(f)
title=next(reader)
high=[]
print('ID'.ljust(15),'NAME'.ljust(15),'RUNS'.ljust(15))
for a,b,c,d in reader:
if int(d)>=100:
high.append(int(d))
print(a.ljust(15),b.ljust(15),d.ljust(15))
if len(high)==0:
print( 'No such records')
else:
print('Average of the top batsmen : ', sum(high)/len(high))
def search():
name=input("Enter player name to be searched : ")
with open("cricket.csv","r") as f:
reader=csv.reader(f)
header=next(reader)
for i in reader:
if i[1]==name:
print("Player found : ",i)
break
else:
print("Player not found ")
def update():
with open('Cricket.csv','r') as f:
c=csv.reader(f)
l=list(c)
pid=input("enter player id to be updated")
for i in l[1:]:
if pid==i[0]:
i[3]=int(input("Enter new no of runs"))
break
else:
print("player not found")
with open('Cricket.csv','w',newline='') as f:
c=csv.writer(f)
c.writerows(l)
menu()
'''Write a program to create a binary file Course.dat
for DIIT training centre to store course information of
all the computer language courses held at their institute.
Each record should be of the form :
[ course_id, course_name, duration(in months), fee].
The program should include the following functionalities:
i) Append new course records to the binary file.
ii) Display all course records from the binary file.
iii) Search for a course by course_id and display its
details, otherwise display an error.
iv) Calculate the average fees of the courses at DIIT
centre.
v) Increase the fees of each course by 10%'''
import pickle
def menu():
while True :
ch=int(input("""MENU :
1) ADD record
2) DISPLAY records
3) SEARCH for record
4) CALCULATE the average fees of the course
5) UPDATE record
6) EXIT
YOUR CHOICE : """))
if ch==1:
add()
elif ch==2:
display()
elif ch==3:
search()
elif ch==4:
calculate()
elif ch==5:
update()
else:
break
def add():
with open('course.dat','ab') as f:
n=int(input("Enter number of records : "))
for i in range(n):
c_id=int(input("Enter course id : "))
c_name=input("Enter course name : ")
duration=int(input("Enter the course duration(months) : "))
fee=int(input("Enter the fees : "))
rec=[c_id,c_name,duration,fee]
pickle.dump(rec,f)
def display():
try:
with open('course.dat','rb') as f:
while True:
rec=pickle.load(f)
print(rec)
except EOFError:
pass
except Exception as e:
print(e)
def search():
c_id=int(input("Enter course id : "))
try:
with open('course.dat','rb') as f:
while True:
rec=pickle.load(f)
if c_id==rec[0]:
print(rec)
break
except EOFError:
print(f"Course no {c_id} not found")
except Exception as e:
print(e)
def calculate():
fees=[]
try:
with open('course.dat','rb') as f:
while True:
rec=pickle.load(f)
fees.append(rec[3])
except EOFError:
avg=sum(fees)/len(fees)
print(f"Average fees ={avg}")
except Exception as e:
print(e)
def update():
l=[]
try:
with open('course.dat','rb') as f:
while True:
rec=pickle.load(f)
rec[3]=rec[3]*1.1
l.append(rec)
except EOFError:
pass
except Exception as e:
print(e)
with open('course.dat','wb') as f:
for rec in l :
pickle.dump(rec,f)
print("Records have been updated ")
display()
menu()