Computer Science Presentation and Program
Computer Science Presentation and Program
DATE:07/11/2024
QUESTION:
QUERIES:
1.
SELECT BORROWER.Customer_Name
FROM BORROWER
INNER JOIN LOAN ON BORROWER.Loan_Number = LOAN.Loan_Number
WHERE LOAN.Branch_Name = 'Downtown';
2.
UPDATE LOAN
SET Amount = 3500
WHERE Loan_Number = 'L-170';
3.
SELECT LOAN.Amount
FROM LOAN
INNER JOIN BORROWER ON LOAN.Loan_Number = BORROWER.Loan_Number
WHERE BORROWER.Customer_Name = 'Hayes';
ATHUL KRISHNA V A
4.
5.
ATHUL KRISHNA V A
PROGRAM-19
DATE:07/11/2024
QUESTION:
QUERIES:
1.
SELECT SUM(Qty) AS Total_Quantity_of_Erasers
FROM STORE
WHERE Item = 'Eraser';
2.
SELECT Item
FROM STORE
WHERE LastBuy < '2010-01-01';
3.
SELECT Item
FROM STORE
ORDER BY Rate ASC;
ATHUL KRISHNA V A
4.
5.
ATHUL KRISHNA V A
PROGRAM-20
DATE:10/11/2024
QUESTION:
QUERIES:
1.
mysql> SELECT DRIVERNAME, DESTINATION
FROM TRANSPORTER
WHERE ITEM = 'TELEVISION';
2.
mysql> SELECT DISTINCT DESTINATION
FROM TRANSPORTER;
3.
mysql> SELECT *
FROM TRANSPORTER
WHERE DRIVERGRADE IS NOT NULL;
ATHUL KRISHNA V A
4.
5.
ATHUL KRISHNA V A
PROGRAM-21
DATE:10/07/2024
QUESTION:
QUERIES:
1.
SELECT NAME, PREWEIGHT, CURRWEIGHT
FROM Gym
WHERE BRANCH = 'MODEL TOWN';
2.
SELECT BRANCH, COUNT(*)
FROM Gym
GROUP BY BRANCH;
3.
SELECT NAME, CURRWEIGHT
FROM Gym
ORDER BY CURRWEIGHT DESC;
ATHUL KRISHNA V A
4.
5.
ATHUL KRISHNA V A
PROGRAM-22
DATE:10/11/2024
QUESTION:
QUERIES:
1.
SELECT NAME, DOJ
FROM Gym
WHERE YEAR(DOJ) = 2018;
2.
SELECT NAME, CURRWEIGHT
FROM Gym
ORDER BY CURRWEIGHT DESC;
3.
SELECT NAME, DOJ
FROM Gym
WHERE GENDER = 'M'
AND DOJ > '2018-09-27';
ATHUL KRISHNA V A
4.
5.
ATHUL KRISHNA V A
PROGRAM -23
DATE:07/11/2024
QUESTION:
To write a Python Program to integrate MYSQL with Python to create Database and Table
to store the details of employees.
PROGRAM CODE:
import mysql.connector
if con.is_connected():
print("Successfully connected to the database.")
cur = con.cursor()
num_records = int(input("How many employee records would you like to enter? "))
for _ in range(num_records):
empid = int(input("Enter employee ID: "))
ename = input("Enter employee name: ")
desg = input("Enter designation: ")
sex = input("Enter sex (M/F): ")
salary = float(input("Enter salary: "))
str = "INSERT INTO employee (empid, ename, desg, sex, sal) VALUES
({},'{}','{}','{}',{})".format(
empid, ename, desg, sex, salary)
cur.execute(str)
con.commit()
else:
print("Connection Error")
con.close()
OUTPUT:
Successfully connected to the database.
How many employee records would you like to enter? 2
Enter employee ID: 101
Enter employee name: John Doe
Enter designation: Software Engineer
Enter sex (M/F): M
ATHUL KRISHNA V A
Enter salary: 75000
Enter employee ID: 102
Enter employee name: Jane Smith
Enter designation: Data Analyst
Enter sex (M/F): F
Enter salary: 65000
2 Employee details inserted successfully.
ATHUL KRISHNA V A
PROGRAM -24
DATE:07/11/2024
QUESTION:
To write a Python Program to integrate MYSQL with Python by inserting records to
Emp table and display the records.
PROGRAM CODE:
import mysql.connector
mycon =
mysql.connector.connect(host="localhost",user="root",passwd="manager",database="employ
ee")
if mycon.is_connected():
print("Successfully connected to the database.")
cursor = mycon.cursor()
num_records = int(input("How many employee records would you like to enter? "))
for _ in range(num_records):
empid = int(input("Enter employee ID: "))
ename = input("Enter employee name: ")
desg = input("Enter designation: ")
sex = input("Enter sex (M/F): ")
salary = float(input("Enter salary: "))
query = "INSERT INTO Emp (empid, ename, desg, sex, salary) VALUES ({}, '{}', '{}',
'{}', {})".format(empid, ename, desg, sex, salary)
cursor.execute(query)
mycon.commit()
print("{} employee records inserted successfully.".format(num_records))
mycon.close()
else:
print("Connection Error")
ATHUL KRISHNA V A
OUTPUT:
How many employee records would you like to enter? 2
Enter employee ID: 101
Enter employee name: John Doe
Enter designation: Manager
Enter sex (M/F): M
Enter salary: 50000
ATHUL KRISHNA V A
PROGRAM -25
DATE:10/11/2024
QUESTION:
To 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
PROGRAM CODE:
import mysql.connector
mycon = mysql.connector.connect(host="localhost",user="root",passwd="manager"
,database="employee")
if mycon.is_connected():
print("Successfully connected to the database.")
cursor = mycon.cursor()
data = cursor.fetchone()
if data:
print("\nEmployee Record Found:")
print(data)
else:
print("No employee found with EmpID {}".format(empid))
mycon.close()
else:
print("Connection Error")
OUTPUT:
CASE 1
Enter the employee ID to search: 101
CASE 2
Enter the employee ID to search: 999
No employee found with EmpID 999
ATHUL KRISHNA V A
PROGRAM-26
DATE:10/02/2024
QUESTION:
To 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.
PROGRAM CODE:
import mysql.connector
mycon = mysql.connector.connect(host="localhost",user="root",passwd="manager"
,database="employee")
if mycon.is_connected():
print("Successfully connected to the database.")
cursor = mycon.cursor()
empid = int(input("Enter the employee ID to search and update the salary: "))
data = cursor.fetchone()
if data:
update_query = "UPDATE Emp SET salary = {} WHERE empid =
{}".format(new_salary, empid)
cursor.execute(update_query)
mycon.commit()
print("Salary updated successfully for EmpID {}".format(empid))
else:
print("No employee found with EmpID {}".format(empid))
mycon.close()
else:
print("Connection Error")
OUTPUT:
ATHUL KRISHNA V A
CASE-1
Enter the employee ID to search and update the salary: 101
Enter the new salary: 60000
CASE-2
Enter the employee ID to search and update the salary: 999
Enter the new salary: 45000
ATHUL KRISHNA V A