Lab Record (2)
Lab Record (2)
Lab Record (2)
AIM:
To create a SCHOOL database with two relations named STUDENT and
GRADE and to perform the following SQL commands.
TABLE: STUDENT
Field Name Data type
Stud_id Int Primary key
stud_name Varchar(20)
Class Char(2)
Sec Char(2)
OUTPUT:
4. Write a query to display all the records order by class and sec.
select * from student order by class,sec;
OUTPUT:
OUTPUT:
8. Write an SQL command to display the maximum mark score in CS exam.
select max(mark) as Highest from result where subject='cs';
OUTPUT:
OUTPUT:
10. Write an SQL query to display subject wise average mark from
result table.
OUTPUT:
MySQL EXERCISE # 2
TABLE: VEHICLE
TABLE: CUSTOMER
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
OUTPUT:
MYSQL Exercise # 3
Aim: - To create an ORG database with three relations named
WORKER, BONUSand TITLE and execute the following SQL commands.
TABLE: WORKER
TABLE: BONUS
TABLE: TITLE
OUTPUT:
2. Write an SQL query to print all Worker details from the
Worker table order by FIRST_NAME Ascending.
AIM:
To create an INVENTORY database with two relations named PRODUCT
and MANUFACTURER and to execute the following SQL commands.
TABLE: MANUFACTURERS
TABLE: PRODUCT
QUESTIONS:
1. Compute the number of products with a price larger than or
equal to 180.
SELECT count (*) from products where price >= 180;
OUTPUT:
2. Select the name and price of all products with a price larger
than or equal to 180, and sort first by price (in descending
order), and then by name (in ascending order).
OUTPUT:
3. Select all the data from the products, including all the data
for each product's manufacturer.
SELECT p.name, p.price,m.name from products p, manufacturers m
where p.manufacturer = m.m_code;
OUTPUT:
OUTPUT
7. Select the name of each manufacturer along with the name and
price of its most expensive product.
Select p.name,p.price,m.name from products p,manufacturers m
where m_code=manufacturer and price=(select max(price) from
products where m_code=manufacturer);
OUTPUT
8. Select the name of each manufacturer which have an average
price above 145 and contain at least 2 different products.
OUTPUT:
OUTPUT:
PYTHON – MySQL Connectivity#1
SOURCE CODE:
import mysql.connector as mysql
def connect_with_mysql():
try:
con=mysql.connect(host="localhost",user="root",password="Vvsn@
123",database="stud")
if con.is_connected():
db_info=con.get_server_info()
print()
except:
print("Connection error")
finally:
if con.is_connected():
con.close()
print("Connection closed")
print("======================================")
connect_with_mysql()
OUTPUT:-
PYTHON – MySQL Connectivity#2
Source Code:-
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="Vvsn@123",database="student")
mycursor=mydb.cursor()
mycursor.execute("Select * from classA")
mydata=mycursor.fetchall()
for i in mydata:
print(i)
print("The total number of rows are fetched:",
mycursor.rowcount)
Output:-
Source Code:-
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="Vvsn@123",database="student")
mycursor=mydb.cursor()
mycursor.execute("Select * from classA")
mydata=mycursor.fetchone()
print(mydata)
print("The total number of rows are fetched:",
mycursor.rowcount)
Output:-
Source Code:-
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",
password="Vvsn@123",database="student")
mycursor=mydb.cursor()
mycursor.execute("Select * from classA")
mydata=mycursor.fetchmany(3)
for i in mydata:
print(i)
print("The total number of rows are fetched:",
mycursor.rowcount)
Output:-