Project 2
Q1.create database alumni;
Q2.All csv files are imported
use alumni;
Q3.select * from college_a_hs;
select * from college_a_se;
select * from college_a_sj;
select * from college_b_hs;
select * from college_b_se;
select * from college_b_sj;
desc college_a_hs;
desc college_a_se;
desc college_a_sj;
desc college_b_hs;
desc college_b_se;
desc college_b_sj;
Q4.import mysql.connector
testdb = mysql.connector.connect(host="localhost",
user = "root",
password = "",
database = "alumni")
testcursor = testdb.cursor()
testcursor.execute("SELECT * FROM college_a_hs LIMIT 1000")
a = testcursor.fetchall()
for b in a:
print(b)
print('-'*100)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="***",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_a_hs limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="Ammukrish",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_a_se limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="Ammukrish",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_a_sj limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="Ammukrish",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_b_hs limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="Ammukrish",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_b_se limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
import mysql.connector
collegedb = mysql.connector.connect(host="localhost",user="root",password="Ammukrish",database="alumni")
collegecursor = collegedb.cursor()
collegecursor.execute("select * from college_b_sj limit 1000")
nj = collegecursor.fetchall()
for a in nj :
print(a)
Q6.
select * from college_a_hs;
Create view college_a_hs_v as select * from college_a_hs Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_a_hs_v;
Q7.
select * from college_a_se;
Create view college_a_se_v as select * from college_a_se Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_a_se_v;
Q8.
select * from college_a_sj;
Create view college_a_sj_v as select * from college_a_sj Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_a_sj_v;
Q9.
select * from college_b_hs;
Create view college_b_hs_v as select * from college_b_hs Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_b_hs_v;
Q10.
select * from college_b_se;
Create view college_b_se_v as select * from college_b_se Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_b_se_v;
Q11.
select * from college_b_sj;
Create view college_b_sj_v as select * from college_b_sj Where RollNo IS NOT NULL AND
LastUpdate IS NOT NULL;
#Selecting Created Views
select * from college_b_sj_v;
Q12.
create view college_A_HS_V AS (select * from college_a_hs where RollNo IS NOT NULL AND LastUpdate IS NOT NULL AND Name IS NOT NULL AND FatherName IS NOT NULL AND MotherName IS NOT NULL
AND Batch IS NOT NULL AND Degree IS NOT NULL AND PresentStatus IS NOT NULL AND HSDegree IS NOT NULL AND EntranceExam IS NOT NULL AND Institute IS NOT NULL AND Location IS NOT NULL);
SELECT * FROM college_A_HS_V;
delimiter $$
create procedure ConvertNameToLower()
begin
select lower(Name),lower(FatherName),lower(MotherName) from College_A_HS_V;
select lower(Name),lower(FatherName),lower(MotherName) from College_A_SE_V;
select lower(Name),lower(FatherName),lower(MotherName) from College_a_sj_v;
select lower(Name),lower(FatherName),lower(MotherName) from College_b_hs_v;
select lower(Name),lower(FatherName),lower(MotherName) from college_b_se_v;
select lower(Name),lower(FatherName),lower(MotherName) from college_b_sj_v;
end $$
delimiter ;
#Calling Stored procedure
call ConvertNameToLower();
Q14.
drop procedure get_name_collegeA
delimiter $$
create procedure get_name_collegeA
(
inout name1 text(40000)
)
begin
declare na int default 0;
declare namelist varchar(16000) default "";
declare namedetail
cursor for
select Name from college_a_hs union select Name from college_a_se union select Name from college_a_sj;
declare continue handler
for not found set na =1;
open namedetail;
getame :
loop
fetch from namedetail into namelist;
if na = 1 then
leave getame;
end if;
set name1 = CONCAT(namelist,";",name1);
end loop getame;
close namedetail;
end $$
DELIMITER ;
set @Name = "";
CALL get_name_collegeA(@Name);
select @Name Name;
Q15.
drop procedure get_name_collegeB
delimiter $$
create procedure get_name_collegeB
(
inout name1 text(40000)
)
begin
declare na int default 0;
declare namelist varchar(16000) default "";
declare namedetail
cursor for
select Name from college_b_hs union select Name from college_b_se union select Name from college_b_sj;
declare continue handler
for not found set na =1;
open namedetail;
getame :
loop
fetch from namedetail into namelist;
if na = 1 then
leave getame;
end if;
set name1 = CONCAT(namelist,";",name1);
end loop getame;
close namedetail;
end $$
DELIMITER ;
set @Name = "";
CALL get_name_collegeB(@Name);
select @Name Name;
Q16.
SET @@sql_mode = sys.list_drop(@@sql_mode, 'ONLY_FULL_GROUP_BY');
select "Higher Studies" Present_status,(count(college_a_hs.RollNo) /(college_a_hs.RollNo))*100 College_A_Persentage,(count(college_b_hs.RollNo)/(college_b_hs.RollNo))*100 College_B_Persentage from college_a_hs cross join college_b_hs union
select "Self Empolyment" Present_status,(count(college_a_se.RollNo) /(college_a_se.RollNo))*100 College_A_Persentage,(count(college_b_se.RollNo)/(college_b_se.RollNo))*100 College_B_Persentage from college_a_se cross join college_b_se union
select "Service Job" Present_status,(count(college_a_sj.RollNo) /(college_a_sj.RollNo))*100 College_A_Persentage,(count(college_b_sj.RollNo)/(college_b_sj.RollNo))*100 College_B_Persentage from college_a_sj cross join college_b_sj;