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

Neeraj

A python program is creating a binary file with student data including name, roll number and marks. It allows inputting new student records and updating the marks of an existing student by searching for them using their roll number. If the roll number is not found, an appropriate message is displayed. The program opens the binary file in append and read mode, dumps new student data dictionaries to the file, and allows loading and updating the data as needed.

Uploaded by

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

Neeraj

A python program is creating a binary file with student data including name, roll number and marks. It allows inputting new student records and updating the marks of an existing student by searching for them using their roll number. If the roll number is not found, an appropriate message is displayed. The program opens the binary file in append and read mode, dumps new student data dictionaries to the file, and allows loading and updating the data as needed.

Uploaded by

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

GOVT CO SARVODAYA

RAJKIYA ED SR SEC SCHOOL, SEC-II, WEST VINOD


BAL VIDYALAYA
DWARKA NAGAR
SCHOOL 1821029
1002005
ID:

COMPUTER SCIENCE
PRACTICAL FILE
Session 2023-24

Name: Neeraj Kumar

Class & Section: XII - A

Roll No: 40

Submitted To: Jitendra Sir


1
R.S.B.V WEST VINOD NAGAR
SESSION: 2023 - 2024

Practical File
Of
Computer Science

Submitted To: Submitted By:


JITENDRA SIR NEERAJ KUMAR
PGT CLASS: XII - A
Computer Science Roll no: 40

2
INDE
X
Sr Pg
No. Practicals No.

Write a python program to input 3 numbers and display the


1 5
largest , smallest number.

2 Write a python program to input a number and check if the 6


number is prime or not.

3
Write a python program to read a text file and display each
7
word separated by ‘#’

Write a python program to read a file and display the nuber


4 8
of vowels, consonants, uppercase, lowercase.

Write a python program to remove the character ‘a’ in a


5 9
line and write it to another file.

Write a python program to create a binary file with


6
employee no., salary and employ ID and display the data 10
on the screen.

Take a sample text file and find the most commonly occuring
7 11
word and frequency of all words.

8 Create a binary file with roll no. , name and marks. Input a roll 12
no. to change marks.

9 Write a python program for a random number genrator that 13


generates a random number between 1-6.

10 Create a binary file with name and roll no. and for a given roll no. 14
display the name if not found3display appropriate message.
2
Sr Pg
No. Practicals No.
Create a csv file with employ ID, name and mobile no. update the
11 15
record by searching with employ ID and display the record.

Create a csv file by entering user id and password search


12 16
and display the password for a given used id.

13 Write a python program to create and search student record in


17
csv file.

14 Write a python program to implement a stack using push and pop


18
operation on stack.

Write a python program using function push(arr) where arr is a


list of numbers. From this list push all the numbers that are
15 divisible by 5 into a stack implemented using a list. Display the 19
stack if it has atleast one element otherwise display appropriate
message.

Write a Python Program to integrate MYSQL with Python to


16 20
create Database and Table to store the details of employees.

Write a Python Program to integrate MYSQL with Python by


17 21
inserting records to Emp table and display the records.
Write a Python Program to integrate MYSQL with Python to
search an Employee using EMPID and display the record if
18 present in already existing table EMP, if not display the
22

appropriate message.

19 SQL COMMANDS EXERCISE - 1 to 5 23

3
Q1.
Write a python program to input 3 numbers and display the largest , smallest number.

num1 = int(input("Write 1st number:


")) num2 = int(input("Write 2nd
number: ")) num3 = int(input("Write
3rd number: ")) def large_num(a,b,c):
if num1>num2 and
num1>num3:
largest_num=num1
elif num2>num1 and
num2>num3:
largest_num=num2
else:
largest_num=num3
print(largest_num, "is largest number")
def small_num(a,b,c):
if num1<num2 and
num1<num3:
smallest_num=num1
elif num2<num1 and
num2<num3:
smallest_num=num2
else:
smallest_num=num3
print(smallest_num, "is smallest
number") large_num(num1,num2,num3)
small_num(num1,num2,num3)

"OUTPUT"
5
Q2.
Write a python program to input a number and check if the number is prime or not.

num = int(input("Enter the number: "))


if num>1:
for i in range(2, num):
if num%i==0:
print(num, "is a composite number")
break
else:
print(num, "is a prime number")
else:
print(num, "is neither prime or composite number")

"OUTPUT"

6
Q3.
Write a python program to read a text file and display each word separated by ‘#’

f = open("files.txt",'r')
read = f.readlines()
for i in read:
n= i.split()
for j in n:
print(j,'#',end="")
print()
f.close()

"OUTPUT"

7
Q4.
Write a python program to read a file and display the nuber of vowels, consonants, uppercase,
lowercase.

f = open("files.txt", 'r')
content = f.read()

vowels = ['a', 'e', '1', '0', 'u', 'A', 'E', '1', '0', 'U']

total_vowels = 0
total_upper = 0
total_lower = 0

for char in content:


if char in vowels:
total_vowels += 1
elif char.isupper():
total_upper += 1
elif char.islower():
total_lower += 1

print("Vowels:", total_vowels,
"Uppercase:", total_upper,
"Lowercase:", total_lower)

f.close()

"OUTPUT"

8
Q5.
Write a python program to remove the character ‘a’ in a line and write it to another file.

f = open("files.txt", 'r')
sir = f.read()
nl = sir.replace('a', ' ')
fx = open('fold.txt', 'w')
fx.write(nl)
print(nl)
f.close()
fx.close()

"OUTPUT"

9
Q6.
Write a python program to create a binary file with employee no., salary and employ ID and
display the data on the screen.

def pro6():
import pickle

def write():
f = open("emp.dat", 'ab')
data = list()
empName = str(input("Name: "))
empId = int(input("ID: "))
empSalary = int(input("Salary in rs: "))
data.append({"Name": empName, "ID": empId, "Salary": empSalary})
pickle.dump(data, f)
f.close()

def read():
f = open("emp.dat", 'rb')
l = pickle.load(f)
print(l)
for i in l:
print('\t', "Name: ", i['Name'], '\n',
'\t', "ID: ", i['ID'], '\n',
'\t', "Salary: ", i['Salary'])

f.close()

write()
read()

pro6()

"OUTPUT"

10
Q7.
Take a sample text file and find the most commonly occuring word and frequency of all words.

from collections import Counter

inputFile = "files.txt"
pro = []

f = open('files.txt', 'r')
for i in f:
w = i.split()
for j in w:
pro.append(j)

cs = Counter(pro) # word frequency -> Counter({"word": frequency})


raj = 0 # max frequency

for k in cs:
if cs[k] > raj:
raj = cs[k]
m = k

print("{", m, "} is the most repeated word in the text file", '\n', '\t', "Frequency of all words", cs)

f.close()

"OUTPUT"

11
Q8.
Create a binary file with roll no. , name and marks. Input a roll no. to change marks.

import pickle

def pro8():
f = open("student.dat", "ab+")
dataDumptoF = {}

def entry():
dataDumptoF["Name"] = str(input("Enter Student name: "))
dataDumptoF["RollNo"] = int(input("Enter roll no: "))
dataDumptoF["Marks"] = float(input("Enter Student Marks: "))
pickle.dump(dataDumptoF, f)

def searchChange():
j = f.tell()
f.seek(0)
l = pickle.load(f)
print(l)
rollNo = int(input("enter the roll no to search: "))
if (l["RollNo"] == rollNo):
l["Marks"] = float(input("Enter marks to be updated: "))
f.seek(j)
pickle.dump(l, f)
print("Student marks updated successfully")
print(l)
else:
print("Roll no. doesn't exist")

entry()
searchChange()

pro8()

"OUTPUT"

12
Q9.
Write a python program for a random number genrator that generates a random number
between 1-6.

import random
for i in range(0,6):
print(random.randint(1,6))

"OUTPUT"

13
Q10.
Create a binary file with name and roll no. and for a given roll no. display the name if
not found display appropriate message.

import pickle

def pro10():
f = open("school.dat",
"ab+") dataDumptoF = {}

def entry():
dataDumptoF["Name"] = str(input("Enter Student name:
")) dataDumptoF["RollNo"] = int(input("Enter roll no:
"))
pickle.dump(dataDumptoF, f)

def search():
f.seek(0)
l = pickle.load(f)
print(l)
rollNo = int(input("enter the roll no to search:
")) if (l["RollNo"] == rollNo):
print(l["Name"])
else:
print("Roll no. doesn't exist")

entry()
search()

f.close()

pro10()

"OUTPUT"

14
Q11. Create a csv file with employ ID, name and mobile no. update the record by searching with
employ ID and display the record.

import csv

def searchEmpByID(empList, targetID):


for index, emp in enumerate(empList):
if len(emp) > 1 and int(emp[1]) == targetID:
return index
return -1

def editEmpRecord(empList, index):


name = input("Enter new name: ")
id = int(input("Enter new ID: "))
mNum = int(input("Enter new mobile no.: "))
empList[index] = [name, id, mNum]

def printEmpRecords(empList):
for i, emp in enumerate(empList, start=1):
if len(emp) > 2:
print("Record", i, '\n', '\tName:', emp[0], '\n', '\tID:', emp[1], '\n', '\tMobile no.:', emp[2])

# Main program
with open('emp.csv', 'a') as f:
l = csv.writer(f)
while True: "OUTPUT
name = input("Name: ")
id = int(input("ID: ")) "
mNum = int(input("Mobile no.: "))
rowsList = [[name, id, mNum]]
l.writerows(rowsList)

con = input("Continue? (yY/nN): ").lower()


if con == 'n':
break

with open('emp.csv', 'r') as fr:


r = csv.reader(fr)
empData = [row for row in r]

printEmpRecords(empData)

sID = int(input("Enter the ID to edit the record: "))


indexToEdit = searchEmpByID(empData, sID)

if indexToEdit != -1:
print("Editing record for ID", sID)
editEmpRecord(empData, indexToEdit)
print("Updated records:")
printEmpRecords(empData)
else:
print("Employee with ID", {sID}, "not found.")

15
Q12.
Create a csv file by entering user id and password search and display the password for a given
used id.

import csv

def searchUserByID(userList, targetID):


for index, user in enumerate(userList):
if int(user[0]) == targetID:
return index
return -1

def printUserRecords(userList):
for i, user in enumerate(userList, start=1):
if len(user) >= 2:
print(f"Record {i}\n\tUser ID: {user[0]}\n\tPassword: {user[1]}\n")
else:
print(f"Record {i} is incomplete and cannot be printed.\n")

# Main program
with open('users.csv', 'a', newline='') as f:
l = csv.writer(f)
numUsers = int(input("Number of users: "))
userRecords = []
for _ in range(numUsers):
userID = int(input("User ID: "))
password = input("Password: ")
userRecords.append([userID, password])

l.writerows(userRecords)

# Read the CSV file again


with open('users.csv', 'r') as fr:
r = csv.reader(fr)
userData = list(r)

if userData and len(userData[0]) >= 2: # Check if the list is not empty and has at least two columns
printUserRecords(userData)

sID = int(input("Enter the User ID to search for: "))


indexToEdit = searchUserByID(userData, sID)

if indexToEdit != -1:
print(f"User with User ID {sID} found.\nUser ID: {userData[indexToEdit][0]}\nPassword: {userData[indexToEdit][1]}")
else:
print(f"User with User ID {sID} not found.")
else:
print("No user records found.")

"OUTPUT"

16
Q13.
Write a python program to create and search student record in csv file.

import csv

def searchStByID(stList, targetRN):


for index, st in enumerate(stList):
if int(st[2]) == targetRN:
return index
return -1

def printStRecords(stList):
for i, st in enumerate(stList, start=1):
print("Record ", i)
print('\tName: ', st[0], '\n\tClass: ', st[1], '\n\tRoll Number:', st[2])

# Main program
with open('students.csv', 'a', newline='') as f:
l = csv.writer(f)
numSt = int(input("Number of Students: "))
stRecords = []
for _ in range(numSt):
name = input("Name: ")
cl = int(input("Class: "))
rollNo = int(input("Roll No.: "))
stRecords.append([name, cl, rollNo])

l.writerows(stRecords)

# Read the CSV file again


with open('students.csv', 'r') as fr:
r = csv.reader(fr)
stData = list(r)

printStRecords(stData)

rollNo = int(input("Enter the Roll Number to search for: "))


indexToEdit = searchStByID(stData, rollNo)

if indexToEdit != -1:
print("Student with Roll Number ", rollNo, "found.")
print("Name: ", stData[indexToEdit][0], '\nClass: ', stData[indexToEdit][1], '\nRoll Number: ', stData[indexToEdit][2])
else:
print("Student with Roll Number ", rollNo, "not found.")

"OUTPUT"

17
Q14.
Write a python program to implement a stack using push and pop operation on stack.

stack = list()

def isEmpty(stack):
if len(stack) == 0:
return True
else:
return False

def push(stack, e):


stack.append(e)

def pop(stack):
if isEmpty(stack):
print("Empty Stack")
return None
else:
stack.pop()

def display(stack):
l = len(stack)
for i in range(l-1, -1, -1):
print(stack[i])

push(stack, "Neeraj")
display(stack)

"OUTPUT"

18
Q15.
Write a python program using function push(arr) where arr is a list of numbers. From this
list push all the numbers that are divisible by 5 into a stack implemented using a list. Display the
stack if it has atleast one element otherwise display appropriate message.

def push(arr):
stack = []
for num in arr:
if num % 5 == 0:
stack.append(num)
return stack

def display_stack(stack):
if len(stack) == 1:
print("The stack has one element:", stack[0])
elif len(stack) > 1:
print("The stack contains the following elements:")
for element in stack:
print(element)
else:
print("The stack is empty.")

input_numbers = input("Enter a list of numbers separated by space: ")


numbers = [int(x) for x in input_numbers.split()]

result_stack = push(numbers)
display_stack(result_stack)

"OUTPUT"

19
Q16.
Write a Python Program to integrate MYSQL with Python to create Database and
Table to store the details of employees.

import mysql.connector

def create_db():
con = None # Initialize con to None

try:
con = mysql.connector.connect(host='localhost', user='root', password='87654321')

if con.is_connected():
cur =
con.cursor()
q = "CREATE DATABASE IF NOT EXISTS employees"
cur.execute(q)
print("Employees database created successfully")

except mysql.connector.Error as err:


print(f"Error: {err}")

finally:
if con is not
None:
con.close()

def create_table():
con = None # Initialize con to None

try:
con = mysql.connector.connect(host='localhost', user='root', password='87654321', database='employees')

if con.is_connected():
cur =
con.cursor()
q = "CREATE TABLE IF NOT EXISTS emp (EMPNO INT PRIMARY KEY, ENAME VARCHAR(20), GENDER VARCHAR(3), SALARY INT)"
cur.execute(q)
print('Emp Table created successfully')

except mysql.connector.Error as err:


print(f"Error: {err}")

finally:
"OUTPUT"
if con is not
None:
con.close()

ch = 'y'

while ch.lower() == 'y':


print("\nInterfacing Python with MySQL")
print("1. To Create Database")
print("2. To Create Table")

opt = int(input("Enter your choice:

")) if opt == 1:
create_db()
elif opt == 2:
create_table()
else:
print("Invalid Choice")

ch = input("Do you want to perform another operation? (y/n):


")
20
Q17.
Write a Python Program to integrate MYSQL with Python by inserting records to
Emp table and display the records.

import mysql.connector

con = mysql.connector.connect(host='localhost', user='root', password='87654321', database='employees')

if con.is_connected():
cur = con.cursor()

opt = 'y'

while opt.lower() == 'y':


No = int(input("Enter Employee Number: "))
Name = input("Enter Employee Name: ")
Gender = input("Enter Employee Gender (M/F): ")
Salary = int(input("Enter Employee Salary: "))

Query = "INSERT INTO EMP VALUES (%s, %s, %s, %s)"


values = (No, Name, Gender, Salary)

cur.execute(Query, values)
con.commit()

print("Record Stored Successfully")

opt = input("Do you want to add another employee details (y/n): ")

Query = "SELECT * FROM EMP"


cur.execute(Query)

data = cur.fetchall()

for i in data:
print(i)

con.close()
"OUTPUT"

21
Q18.
Write a Python Program to integrate MYSQL with Python to search an Employee using
EMPID and display the record if present in already existing table EMP, if not display the
appropriate message.

import mysql.connector

con = mysql.connector.connect(host='localhost', user='root', password='87654321', database='employees')

if con.is_connected():
cur = con.cursor()

print("\nWelcome to Employee Search Screen")

No = int(input("\nEnter the employee number to search: "))

Query = "SELECT * FROM EMP WHERE Ename = {}".format(No)

cur.execute(Query)

data = cur.fetchone()

if data is not None:


print(data)
else:
print("Record not Found!")

con.close()

"OUTPUT"

22
Q19.
Write a Python Program to integrate MYSQL with Python to search an Employee
using EMPID and update the Salary of an employee if present in already existing
table
EMP, if not display the appropriate message.

import mysql.connector

con = mysql.connector.connect(host='localhost', user='root', password='87654321', database='employee')

if con.is_connected():
cur = con.cursor()

print("Welcome to Employee detail update Screen")

Eno = int(input("Enter the employee number to

Update:")) Query = "SELECT * FROM EMP WHERE

Eno={}".format(Eno)

cur.execute(Query)
data = cur.fetchone()

if data is not None:


print("Record found details are:")
print(data)

ans = input("Do you want to update the Salary of the above employee

(y/n)?:") if ans.lower() == 'y':


New_Sal = int(input("Enter the New Salary of an Employee:"))
Q1 = "UPDATE EMP SET SALARY={} WHERE Eno={}".format(New_Sal, Eno)
cur.execute(Q1)
con.commit()
print("Employee Salary Updated Successfully")

Q2 = "SELECT * FROM EMP"


cur.execute(Q2)
data = cur.fetchall()

for i in data:
print(i)
else:
print("Record not Found!!!")

con.close()
"OUTPUT"
23
SQL COMMANDS EXERCISE - 1
Ex.No: 20
DATE:

AIM: Q20.
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to Create a new database in the name of "STUDENTS".

CREATE DATABASE STUDENTS;

(b) Write a Query to Open the database "STUDENTS".

USE STUDENTS;

(c) Write a Query to create the above table called: "STU"

CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10),


GENDER VARCHAR(3), AGE INT,DEPT VARCHAR(15),
DOA DATE,FEES INT);

(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:

3
24
SQL COMMANDS EXERCISE - 2
Ex.No: 21
DATE:

AIM: Q21.
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to insert all the rows of above table into Info table.

INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);

INSERT INTO STU VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);

INSERT INTO STU VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);

INSERT INTO STU VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);

INSERT INTO STU VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);

INSERT INTO STU VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);

INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);

INSERT INTO STU VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);

(b) Write a Query to display all the details of the Employees from the above table 'STU'.

SELECT * FROM STU;

Output:

3
25
(c) Write a query to Rollno, Name and Department of the students from STU table.

SELECT ROLLNO,NAME,DEPT FROM STU;

Output:

(d) Write a Query to select distinct Department from STU table.

SELECT DISTICT(DEPT) FROM STU;

Output:

(e) To show all information about students of History department.

SELECT * FROM STU WHERE DEPT='HISTORY';

Output:

********************************************************************************************

26
3
Ex.No: 22 SQL COMMANDS EXERCISE - 3

DATE:

AIM:
Q22.
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to list name of female students in Hindi Department.

SELECT NAME FROM STU WHERE DEPT='HINDI' AND GENDER='F';

Output:

(b) Write a Query to list name of the students whose ages are between 18 to 20.

SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;

Output:

3
27
(c) Write a Query to display the name of the students whose name is starting with 'A'.

SELECT NAME FROM STU WHERE NAME LIKE 'A%';

Output:

(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.

SELECT NAME FROM STU WHERE NAME LIKE '_N%';

Output:

**********************************************************************************************************

28
3
Ex.No: 23 SQL COMMANDS EXERCISE - 4

DATE:

AIM:
Q23.
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to delete the details of Roll number is 8.

DELETE FROM STU WHERE ROLLNO=8;

Output (After Deletion):

(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.

UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;

Output(After Update):

4
29
(c) Write a Query to add a new column Area of type varchar in table STU.

ALTER TABLE STU ADD AREA VARCHAR(20);

Output:

(d) Write a Query to Display Name of all students whose Area Contains NULL.

SELECT NAME FROM STU WHERE AREA IS NULL;

Output:

(e) Write a Query to delete Area Column from the table STU.

ALTER TABLE STU DROP AREA;

Output:

(f) Write a Query to delete table from Database.

DROP TABLE STU;

Output:
*******************************************************************************************

430
Ex.No: 24 SQL COMMANDS EXERCISE - 5
DATE:

AIM: Q24.
To write Queries for the following Questions based on the given table:
TABLE: UNIFORM

Ucode Uname Ucolor StockDate


1 Shirt White 2021-03-31
2 Pant Black 2020-01-01
3 Skirt Grey 2021-02-18
4 Tie Blue 2019-01-01
5 Socks Blue 2019-03-19
6 Belt Black 2017-12-09

TABLE: COST

Ucode Size Price Company


1 M 500 Raymond
1 L 580 Mattex
2 XL 620 Mattex
2 M 810 Yasin
2 L 940 Raymond
3 M 770 Yasin
3 L 830 Galin
4 S 150 Mattex

(a) To Display the average price of all the Uniform of Raymond Company from table COST.

SELECT AVG(PRICE) FROM COST WHERE COMPANY='RAYMOND';

Output:

(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.

SELECT * FROM UNIFORM ORDER BY STOCKDATE DESC;

Output:

4
31
(c) To Display max price and min price of each company.

SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY COMPANY;

Output:

(d) To display the company where the number of uniforms size is more than 2.

SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING COUNT(*)>2;

Output:

(e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.

SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM UNIFORM U,COST C WHERE


U.UCODE=C.UCODE;

Output:

*****************************************************************************************

432

You might also like