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

sql handsonsolution_nkv

Uploaded by

kumar99.vallam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

sql handsonsolution_nkv

Uploaded by

kumar99.vallam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Exercise 1:

Trainer_Info :
CREATE TABLE Trainer_Info
(Trainer_Id char(20) unique,
Salutation char(7) not null,
Trainer_Name char(30) not null,
Trainer_Location char(30) not null,
Trainer_Track char(15) not null,
Trainer_Qualification char(100) not null,
Trainer_Experiance int(11) not null,
Trainer_Email char(100) not null,
Trainer_Password char(20) not null
);

Batch_Info :
CREATE TABLE Batch_Info
(Batch_Id char(20) unique,
Batch_Owner char(30) not null,
Batch_BU_Name char(30) not null
);

CREATE TABLE Module_Info :


CREATE TABLE Module_Info
(Module_Id char(20) unique,
Module_Name char(40) not null,
Module_Duration int(11) not null );

CREATE TABLE Associate_Info :


CREATE TABLE Associate_Info
(Associate_Id char(20) unique,
Salutation char(7) not null,
Associate_Name char(30) not null,
Associate_Location char(30) not null,
Associate_Track char(15) not null,
Associate_Qualification char(200) not null,
Associate_Email char(100) not null,
Associate_Password char(20) not null
);

CREATE TABLE Questions :


CREATE TABLE Questions
(Question_Id char(20) primary key unique,
Module_Id char(20) not null,
Question_Text varchar(900) not null,
foreign key (Module_Id) references Module_Info(Module_Id)
);

CREATE TABLE Associate_Status :


Create table Associate_Status(
Associate_Id char(20)
references Associate_Info(Associate_Id), Module_Id char(20)
references module_Info(Module_Id),
batch_Id Char(20),
Trainer_Id Char(20),
Start_Date char(20),
End_Date Char(20)
);
CREATE TABLE Trainer_Feedback
CREATE TABLE Trainer_Feedback
(Trainer_Id char(20) references Trainer_Info(Trainer_Id),
Question_Id char(20) not null,
Batch_Id char(20) not null,
Module_Id char(20) not null,
Trainer_Rating int(11) not null
);

CREATE TABLE Associate_Feedback :


CREATE TABLE Associate_Feedback
(Associate_Id char(20) references Associate_Info(Associate_Id),
Question_Id char(20) not null,
Module_Id char(20) not null,
Associate_Rating int(11) not null);
CREATE TABLE Login_Details :
CREATE TABLE Login_Details
(User_Id char(20) not null,
User_Password char(30) not null
);

EXERCISE 2:
Insert below details into table:
Table Trainer_Info:
INSERT INTO Trainer_Info VALUES ('F001','Mr.','PANKAJ
GHOSH','Pune','Java','Bachelor of
Technology',12,'[email protected]','fac1@123');
INSERT INTO Trainer_Info VALUES ('F002','Mr.','SANJAY
RADHAKRISHNAN','Bangalore','DotNet','Bachelor of
Technology',12,'[email protected]','fac2@123');
INSERT INTO Trainer_Info VALUES
('F003','Mr.','VIJAY MATHUR','Chennai','Mainframe','Bachelor of
Technology',10,'[email protected]','fac3@123');
INSERT INTO Trainer_Info VALUES ('F004','Mrs.','NANDINI
NAIR','Kolkata','Java','Master of Computer
Applications',9,'[email protected]','fac4@123');
INSERT INTO Trainer_Info VALUES
('F005','Miss.','ANITHA PAREKH','Hyderabad','Testing','Master of Computer
Applications',6,'[email protected]','fac5@123');
INSERT INTO Trainer_Info VALUES ('F006','Mr.','MANOJ AGRAWAL'
,'Mumbai','Mainframe','Bachelor of
Technology',9,'[email protected]','fac6@123');
INSERT INTO Trainer_Info VALUES
('F007','Ms.','MEENA KULKARNI','Coimbatore','Testing','Bachelor of
Technology',5,'[email protected]','fac7@123');
INSERT INTO Trainer_Info VALUES ('F009','Mr.','SAGAR
MENON','Mumbai','Java','Master of Science In Information
Technology',12,'[email protected]','fac8@123');

Insert values into table Batch_info:


INSERT INTO Batch_Info VALUES ('B001','MRS.SWATI ROY','MSP');
INSERT INTO Batch_Info VALUES ('B002','MRS.ARURNA K','HEALTHCARE');
INSERT INTO Batch_Info VALUES ('B003','MR.RAJESH KRISHNAN','LIFE
SCIENCES'); INSERT INTO Batch_Info VALUES ('B004','MR.SACHIN
SHETTY','BFS');
INSERT INTO Batch_Info VALUES ('B005','MR.RAMESH
PATEL','COMMUNICATIONS'); INSERT INTO Batch_Info VALUES
('B006','MRS.SUSAN CHERIAN','RETAIL & HOSPITALIT'); INSERT INTO
Batch_Info VALUES ('B007','MRS.SAMPADA JAIN','MSP');
INSERT INTO Batch_Info VALUES ('B008','MRS.KAVITA
REGE','BPO'); INSERT INTO Batch_Info VALUES
('B009','MR.RAVI SEJPAL','MSP');

Insert values into Module_Info:


INSERT INTO Module_Info VALUES ('O10SQL','Oracle 10g SQL
',16); INSERT INTO Module_Info VALUES ('O10PLSQL','Oracle
10g PL/ SQL' ,16); INSERT INTO Module_Info VALUES
('J2SE','Core Java SE 1.6',288);
INSERT INTO Module_Info VALUES ('J2EE','Advanced Java EE
1.6',80); INSERT INTO Module_Info VALUES ('DOTNT4','.Net
Framework 4.0' ,5); INSERT INTO Module_Info VALUES
('SQL2008','MS SQl Server 2008',120); INSERT INTO
Module_Info VALUES ('MSBI08','MS BI Studio 2008',158);
INSERT INTO Module_Info VALUES ('SHRPNT','MS Share Point'
,80); INSERT INTO Module_Info VALUES ('ANDRD4','Android
4.0',200);
INSERT INTO Module_Info VALUES
('EM001','Instructor',0); INSERT INTO Module_Info
VALUES ('EM002','Course Material',0);
INSERT INTO Module_Info VALUES ('EM003','Learning
Effectiveness',0); INSERT INTO Module_Info VALUES
('EM004','Environment',0);
INSERT INTO Module_Info VALUES ('EM005','Job
Impact',0); INSERT INTO Module_Info VALUES
('TM001','Attendees',0); INSERT INTO Module_Info
VALUES ('TM002','Course Material',0); INSERT INTO
Module_Info VALUES ('TM003','Environment',0);

INSERT value into Associate_Info :


INSERT INTO Associate_Info VALUES
('A001','Miss.','GAYATHRI
NARAYANAN','Gurgaon','Java','Bachelor of
Technology','[email protected]','tne1@123');
INSERT INTO Associate_Info VALUES
('A002','Mrs.','RADHIKA MOHAN','Kerala','Java','Bachelor of Engineering In
Information Technology','[email protected]','tne2@12');
INSERT INTO Associate_Info VALUES
('A003','Mr.','KISHORE SRINIVAS','Chennai','Java','Bachelor of
Engineering In
Computers','[email protected]','tne3@123');
INSERT INTO Associate_Info VALUES ('A004','Mr.','ANAND
RANGANATHAN','Mumbai','DotNet','Master of Computer
Applications','[email protected]','tne4@123');
INSERT INTO Associate_Info VALUES
('A005','Miss.','LEELA MENON','Kerala','Mainframe','Bachelor of Engineering In
Information Technology','[email protected]','tne5@123');
INSERT INTO Associate_Info VALUES
('A006','Mrs.','ARTI KRISHNAN','Pune','Testing','Master of Computer
Applications','[email protected]','tne6@123');
INSERT INTO Associate_Info VALUES
('A007','Mr.','PRABHAKAR SHUNMUGHAM','Mumbai','Java','Bachelor of
Technology','[email protected]','tne7@123');

INSERT INTO VALUES Questions :


INSERT INTO Questions VALUES ('Q001','EM001','Instructor knowledgeable
and able to handle all your queries.');
INSERT INTO Questions VALUES ('Q002','EM001','All the topics in a particular
course handled by the trainer without any gaps or slippages.');
INSERT INTO Questions VALUES ('Q003','EM002','The course materials
presentation, handson, etc. refered during the training are relevant and
useful.');
INSERT INTO Questions VALUES ('Q004','EM002','The Hands on session
adequate enough to grasp the understanding of the topic.');
INSERT INTO Questions VALUES ('Q005','EM002','The reference materials
suggested for each module are adequate.');
INSERT INTO Questions VALUES ('Q006','EM003','Knowledge and skills
presented in this training are applicatible at your work.');
INSERT INTO Questions VALUES ('Q007','EM003','This training increases my
proficiency level.');
INSERT INTO Questions VALUES ('Q008','EM004','The physical environment
e.g. classroom space, air-conditioning was conducive to learning.');
INSERT INTO Questions VALUES ('Q009','EM004','The software/hardware
environment provided was sufficient for the purpose of the training.');
INSERT INTO Questions VALUES ('Q010','EM005','This training will improve your job
performance.');
INSERT INTO Questions VALUES ('Q011','EM005','This training align with
the business priorities and goals.');
INSERT INTO Questions VALUES ('Q012','TM001','Participants were
receptive and had attitude towards learning.');
INSERT INTO Questions VALUES ('Q013','TM001','All participats gained the
knowledge and the practical skills after this training.');
INSERT INTO Questions VALUES ('Q014','TM002','The course materials
presentation, handson, etc. available for the session covers the entire
objectives of the course.');
INSERT INTO Questions VALUES ('Q015','TM002','Complexity of the course is
adequate for the particpate level.');
INSERT INTO Questions VALUES ('Q016','TM002','Case study and practical
demos helpful in understanding of the topic.');
INSERT INTO Questions VALUES ('Q017','TM003','The physical environment e.g.
classroom space, air-conditioning was conducive to learning.');
INSERT INTO Questions VALUES ('Q018','TM003','The software/hardware
environment provided was adequate for the purpose of the training.');

Insert values into table Associate_Status :


INSERT INTO Associate_Status VALUES
('A001','O10SQL','B001','F001','2000-12-15','2000-12- 25');
INSERT INTO Associate_Status VALUES
('A002','O10SQL','B001','F001','2000-12-15','2000-12- 25');
INSERT INTO Associate_Status VALUES
('A003','O10SQL','B001','F001','2000-12-15','2000-12- 25');
INSERT INTO Associate_Status VALUES
('A001','O10PLSQL','B002','F002','2001-2-1','2001-2- 12');
INSERT INTO Associate_Status VALUES
('A002','O10PLSQL','B002','F002','2001-2-1','2001-2- 12');
INSERT INTO Associate_Status VALUES
('A003','O10PLSQL','B002','F002','2001-2-1','2001-2- 12');
INSERT INTO Associate_Status VALUES
('A001','J2SE','B003','F003','2002-8-20','2002-10-25'); INSERT INTO
Associate_Status VALUES ('A002','J2SE','B003','F003','2002-8-20','2002-10-25');
INSERT INTO Associate_Status VALUES
('A001','J2EE','B004','F004','2005-12-1','2005-12-25'); INSERT INTO
Associate_Status VALUES ('A002','J2EE','B004','F004','2005-12-1','2005-12-25');
INSERT INTO Associate_Status VALUES
('A003','J2EE','B004','F004','2005-12-1','2005-12-25'); INSERT INTO
Associate_Status VALUES ('A004','J2EE','B004','F004','2005-12-1','2005-12-25');
INSERT INTO Associate_Status VALUES
('A005','JAVAFX','B005','F006','2005-12-4','2005-12- 20');
INSERT INTO Associate_Status VALUES
('A006','JAVAFX','B005','F006','2005-12-4','2005-12- 20');
INSERT INTO Associate_Status VALUES
('A006','SQL2008','B006','F007','2007-6-21','2007-6- 28');
INSERT INTO Associate_Status VALUES
('A007','SQL2008','B006','F007','2007-6-21','2007-6- 28');
INSERT INTO Associate_Status VALUES
('A002','MSBI08','B007','F006','2009-6-26','2009-6- 29');
INSERT INTO Associate_Status VALUES
('A003','MSBI08','B007','F006','2009-6-26','2009-6- 29');
INSERT INTO Associate_Status VALUES
('A004','MSBI08','B007','F006','2009-6-26','2009-6- 29');
INSERT INTO Associate_Status VALUES
('A002','ANDRD4','B008','F005','2010-6-5','2010-6- 28');
INSERT INTO Associate_Status VALUES
('A005','ANDRD4','B008','F005','2010-6-5','2010-6- 28');
INSERT INTO Associate_Status VALUES
('A003','ANDRD4','B009','F005','2011-8-1','2011-8- 20');
INSERT INTO Associate_Status VALUES
('A006','ANDRD4','B009','F005','2011-8-1','2011-8- 20');

EXERCISE 3:
update Trainer_Info set Trainer_Password= 'nn4@123'
where Trainer_Id= 'F004';

EXERCISE 4:
delete from associate_status
where Associate_Id="A003" and Module_Id="J2EE";

EXERCISE 5:
select * from trainer_info
order by Trainer_Experiance desc
limit 5;

EXERCISE 6:
start transaction;

Insert into login_details values('U001','Admin1@123');


insert into login_details values('U002','Admin2@123');
select * from login_details;
rollback;

EXERCISE 7:

Create user ‘arnab’@ 'localhost’identified by ‘pccvbh123’;


Grant select on dw_062.trainer_feedback to ‘arnab’@ ‘localhost’;
Grant Create on dw_062.trainer_feedback to ‘arnab’@ ‘localhost’;
Show grants for ‘arnab’@ ‘localhost’;

Revoke select,create on dw_062.trainer_feedback from ‘arnab’@ ‘localhost’;


Show grants for ‘arnab’@ ‘localhost’;

EXERCISE 8:

drop table login_details;

EXERCISE 9:

Create table suppliers


( supplier_id numeric(10) not null,
supplier_name varchar(50) not null,
address varchar(50),
city varchar(50),
state varchar(25),
zip_code varchar(10)
);

The Prequisite:

Create table Course_Fees


( Course_code varchar(50),
Base_fees numeric(50),
Special_fees numeric(50),
Discount numeric(20)
);
INSERT INTO COURSE_FEES VALUES ('1',180,100,10);
INSERT INTO COURSE_FEES VALUES ('2',150,110,10);
INSERT INTO COURSE_FEES VALUES ('3',160,170,5);
INSERT INTO COURSE_FEES VALUES ('4',150,100,10);
INSERT INTO COURSE_FEES VALUES ('6',190,100,40);

Create table COURSE_FEES_HISTORY


( Course_code varchar(50),
Base_fees numeric(50),
Special_fees numeric(50),
Created_By varchar(50),
Updated_By varchar(50)
);

INSERT INTO Course_Fees_History VALUES ('1',120,123,'Ram','Ramesh');


INSERT INTO Course_Fees_History VALUES ('2',150,110,'Bala','Ram');
INSERT INTO Course_Fees_History VALUES ('3',160,170,'Bala','vinu');
INSERT INTO Course_Fees_History VALUES ('4',170,235,'Ram','Ram');
INSERT INTO Course_Fees_History VALUES ('5',190,100,'Vinod','Vinod');

EXERCISE 10:
select a.course_code,a.base_fees,a.special_fees
from course_fees a left join course_fees_history b
on a.course_code = b.course_code
union
select a.course_code,a.base_fees,a.special_fees
from course_fees_history a right join course_fees b
on a.course_code = b.course_code;

EXERCISE 11:

select distinct course_code,base_fees,special_fees from course_fees


union
select distinct course_code,base_fees,special_fees from course_fees_history;

PREREQUISITE:

Create table COURSE_INFO(


COURSE_CODE varchar(10) primary key,
COURSE_NAME varchar(20) not null,
COURSE_DESCRIPTION varchar (25),
COURSE_START_DATE date,
COURSE_DURATION int,
NO_OF_PARTICIPANTS int,
COURSE_TYPE char(3));

Create table STUDENT_INFO(


STUDENT_ID varchar(10) primary key,
FIRST_NAME varchar(20),
LAST_NAME varchar(25),
ADDRESS varchar(150)
);
insert into course_fees (base_fees) values (null);
insert into course_fees (base_fees) values (null);
insert into course_fees (base_fees) values (300);
insert into course_fees (base_fees) values (175);
EXERCISE 12:
select min(base_fees) from course_fees;
select max(base_fees) from course_fees;

PREREQUISITE:
alter table course_fees
add infra_fees decimal(5,3);

insert into course_fees (infra_fees) values


(45.751); insert into course_fees (infra_fees)
values (43.471); insert into course_fees
(infra_fees) values (42.631); insert into
course_fees (infra_fees) values (41.981); insert
into course_fees (infra_fees) values (40.781);

Exercise 13:
select avg(infra_fees) from course_fees;

Exercise 14:
select course_name, datediff (curdate(), course_start_date) from course_info;

Exercise 15:
select (COURSE_CODE , COURSE_NAME) as COURSES from course_info;

Exercise 16:
select avg(ifnull(base_fees,0)) from course_fees;
Pre-requisite:

insert into course_info values(1,'History','Indian history','2020-06-


15',4,37,'clr');
insert into course_info values(2, 'Maths', 'Set theory','2020-04-29',3,17,'el');
insert into course_info values(3,'physics','Light concepts','2020-10-
10',5,37,'of');

Exercise 17:
Select course_type ,
Case when course_type = 'clr' then 'class room'
When course_type = 'el' then 'elearing'
When course_type = 'of' then 'offline reading'
End as Message
From course_info;

Exercise 18:
select COURSE_START_DATE,sum(NO_OF_PARTICIPANTS) as "Total
number of students" from COURSE_INFO
group by COURSE_START_DATE;

Exercise 19:
select COURSE_START_DATE,COURSE_TYPE,sum(NO_OF_PARTICIPANTS)
as "Total number of students" from COURSE_INFO
group by COURSE_START_DATE
having COURSE_TYPE ='CLR';

Exercise 20:
select COURSE_START_DATE,COURSE_TYPE,sum(NO_OF_PARTICIPANTS) as
"Total number of students" from COURSE_INFO
group by COURSE_START_DATE
having COURSE_TYPE ='CLR' and sum(NO_OF_PARTICIPANTS)>10;

Exercise 21:
select COURSE_NAME from course_info
order by COURSE_DURATION desc;

Exercise 22:
SELECT ss.STUDENT_ID,ss.first_name,ss.last_name,cc.course_code
from student_info ss join student_courses cc
on cc.student_id=ss.STUDENT_ID
where cc.course_code=167;

Exercise 23:
Select c.discount,cc.course_name,cc.COURSE_DESCRIPTION from course_fees c

join course_info cc on c.course_code=cc.COURSE_CODE;

EXERCISE 24:
SELECT FIRST_NAME, COURSE_CODE FROM STUDENT_INFO SS
LEFT JOIN COURSE_INFO CC ON SS.STUDENT_ID = CI.STUDENT_ID;

PREREQUISITE:
INSERT INTO COURSE_INFO VALUES(4,'ACCOUNTANCY',' FUNDAMENTAL
CONCEPTS','2020-04-18',8,27,'CLR');

INSERT INTO COURSE_INFO VALUES(5,'ECONOMICS','THEORY CONCEPTS','2020-04-


18',10,26,'OF');
INSERT INTO COURSE_FEES (COURSE_CODE,BASE_FEES , SPECIAL_FEES ) VALUES
(5,350,248) , (6,354,156);

INSERT INTO STUDENT_INFO VALUES('255266', 'Anil','Kumar',' college,STREET');


INSERT INTO STUDENT_INFO VALUES('251022', 'Amit','Agarwal','Hospital colony');

EXERCISE 25:
select ss.student_id
from student_info ss join course_fees cf
on ss.course_code=cf.course_code
where cf.base_fees<1500;

EXERCISE 26:
select ss.student_id,ss.concat(first_name,” “,last_name)
from student_info ss join course_fees cf
on ss.course_code=cf.course_code
where cf.base_fees<1500;

You might also like