Você está na página 1de 11

create database EmployeeProMangt

use EmployeeProMangt

create table tblDepartment

deptno integer,

dept_name varchar(20),

constraint constraint_pkdepno primary key(deptno)

drop table tblDepartment

create table tblCity

cityid integer,

cityname varchar(20),

statename varchar(20),

country varchar(20),

constraint constraint_pkcid primary key(cityid)

drop table tblCity

create table tblProject

project_no integer,
project_name varchar(20),

complete_status varchar(20),

constraint constraint_pkprono primary key(project_no)

drop table tblProject

create table tblCompanyLocation

location_id integer,

location_name varchar(20),

address1 varchar(20),

address2 varchar(20),

pin integer,

cityid integer,

constraint constraint_pkloid primary key(location_id),

constraint constraint_fkciid foreign key(cityid) references tblCity(cityid)

drop table tblCompanyLocation

create table tblEmployee

emp_no integer,
emp_firstname varchar(20),

emp_lastname varchar(20),

hiredate date,

job varchar(20),

mgr_no integer,

currentprojectno integer,

sal integer,

comm varchar(20),

deptno integer,

comp_locationid integer,

constraint constraint_pkempno primary key(emp_no)

alter table tblEmployee add constraint constraint_fkloid foreign key(comp_locationid) references


tblCompanyLocation(location_id)

alter table tblEmployee add constraint constraint_fkdepno foreign key(deptno) references


tblDepartment(deptno)

alter table tblEmployee add constraint constraint_fkprno foreign key(currentprojectno) references


tblProject(project_no)

drop table tblEmployee

create table tblProjectHistory

empno integer,

projectno integer,

startdate date,
enddate date

alter table tblProjectHistory add constraint constraint_fkempno foreign key(empno) references


tblEmployee(emp_no)

alter table tblProjectHistory add constraint constraint_fkprono foreign key(projectno) references


tblProject(project_no)

drop table tblProjectHistory

select * from tblDepartment

insert into tblDepartment values(101,'Testing')

insert into tblDepartment values(102,'Manufacturing')

insert into tblDepartment values(103,'Developing')

insert into tblDepartment values(104,'Testing')

insert into tblDepartment values(105,'Testing')

select * from tblCity

insert into tblCity values(201,'Chennai','Tamilnadu','country')


insert into tblCity values(202,'Hyderabad','AP','india')

insert into tblCity values(203,'Bangalore','Karnadaka','india')

insert into tblCity values(204,'Chennai','Tamilnadu','india')

insert into tblCity values(205,'Newyork','Tamilnadu','USA')

select * from tblProject

insert into tblProject values(301,'Cosdes','Designing')

insert into tblProject values(302,'Spam detection','Completed')

insert into tblProject values(303,'Network introder','Completed')

insert into tblProject values(304,'Automatic room clean','documentation')

select * from tblCompanyLocation

insert into tblCompanyLocation values(401,'Chennai','mepz','thambaram',638703,201)

insert into tblCompanyLocation values(402,'Chennai','mepz','thambaram',638703,202)

insert into tblCompanyLocation values(403,'Bangalore','dlfx','madivala',632223,203)

insert into tblCompanyLocation values(404,'Chennai','IT park','siruseri',632223,201)

insert into tblCompanyLocation values(404,'Chennai','IT park','siruseri',632223,201)


select * from tblEmployee

insert into tblEmployee values(501,'Kowsalya','Rajan','2011-03-02','Programmer


analyst',601,301,22000,'insurence',101,401)

insert into tblEmployee values(502,'Yoga','Rajan','2011-04-22','Programmer


analyst',602,302,22000,'insurence',102,402)

insert into tblEmployee values(503,'Priya','Ganesh','2013-02-26','Programmer


analyst',603,301,25000,'bfs',102,402)

insert into tblEmployee values(504,'Kirthi','Sampath','2013-02-26','Programmer


analyst',602,303,25000,'bfs',102,403)

insert into tblEmployee values(505,'Sobana','Sampath','2018-02-26','Programmer


analyst',602,303,25000,'bfs',102,403)

select * from tblProjectHistory

insert into tblProjectHistory values(501,301,'2013-02-26','2013-05-26')

insert into tblProjectHistory values(502,302,'2012-01-20','2012-05-26')

insert into tblProjectHistory values(503,303,'2012-10-26','2013-01-26')

/*1. Select employee detail who are all join on 2008 year*/
select * from tblEmployee where extract(year from hiredate)='2018'

/*2. who are all not yet allocated into the project display empNo,FullName.*/

select tem.emp_no,concat(tem.emp_firstname,tem.emp_lastname) "Full Name" from tblEmployee tem

left outer join tblProjectHistory tph on tem.emp_no=tph.empno where tph.projectno is NULL

/*3. The employee id is 2361(You can use ur managerId) select employeename,salary,and


managerName and projectName */

select concat(temp.emp_firstname,temp.emp_lastname) "Full


Name",temp.sal,temp.mgr_no,tp.project_name from tblProject tp

join tblEmployee temp on tp.project_no = temp.currentprojectno where temp.emp_no=501

/*4. Who are all not getting commition select empname,id */

select * from tblEmployee where comm is NULL

/*5. If employeeid is 2361 display the employee id,name,projectname,startdate,enddate,and


locationname */

select * from tblCompanyLocation tcl

join tblEmployee temp on tcl. location_id = temp.comp_locationid

join tblProjectHistory tph on temp.emp_no=tph.empno

join tblProject tp on tp.project_no=tph.projectno where temp.emp_no=501


/*6.Currently what are all the project are running in siruseri location display
projectName,startdate,Enddate */

select distinct tpro.project_name,tph.startdate,tph.enddate from tblProject tpro

join tblProjectHistory tph on tpro.project_no=tph.projectno

join tblEmployee temp on tph.projectno=temp.currentprojectno

join tblCompanyLocation tcl on tcl. location_id = temp.comp_locationid where tcl.address2='madivala'

/*7.display how much we are spending for each project(Only for salary)*/

select currentprojectno,sum(sal) "Spending" from tblEmployee group by currentprojectno

/* to display the project name also*/

select tp.project_name,sum(temp.sal) "Spending" from tblEmployee temp

join tblProject tp on temp.currentprojectno=tp.project_no group by temp.currentprojectno

/*8.To which project we are spending more( only salary)*/

select currentprojectno,max(S) "Spending" from (select currentprojectno,sum(sal) "S" from tblEmployee


group by currentprojectno) t1

/* to display the project name also*/

select project_name,max(S) "Spending" from (select tp.project_name,sum(temp.sal) "S" from


tblEmployee temp

join tblProject tp on temp.currentprojectno=tp.project_no group by temp.currentprojectno) t1

/*9.In BFS/spamdetection Project Who are woking And their experience detail*/

select * from tblProjectHistory tph

join tblProject tp on tph.projectno=tp.project_no where tp.project_name='Cosdes'


select period_diff('startdate','enddate') "Experience" from tblProjectHistory

/*10. Select pincode for Chennai*/

select pin from tblCompanyLocation where location_name like 'Chennai'

/*11. The employee who do not live in Chennai display employeeid and name*/

select emp_no,concat(emp_firstname,emp_lastname) "NAME" from tblEmployee temp

join tblCompanyLocation tcl on temp.comp_locationid=tcl.location_id

join tblCity tc on tcl.cityid=tc.cityid where tc.cityname like'Chennai'

/*12. To get list of employee Who where hired after 12-may-2012(you can give ur own date)*/

select concat(emp_firstname,emp_lastname) "NAME" from tblEmployee where hiredate > '2012-05-12'

/*13. The employee who live in Chennai and bangalore, hyderabad display employeeName and id*/

select emp_no,concat(emp_firstname,emp_lastname) "NAME" from tblEmployee temp

join tblCompanyLocation tcl on temp.comp_locationid=tcl.location_id

join tblCity tc on tcl.cityid=tc.cityid where tc.cityname in('chennai','bangalore','hyderabed');

select * from tblcity

/*

14. The employee who do not live in Chennai and bangalore, hyderabad display employeeName and
id

*/
select emp_no,concat(emp_firstname,emp_lastname) "NAME" from tblEmployee temp

join tblCompanyLocation tcl on temp.comp_locationid=tcl.location_id

join tblCity tc on tcl.cityid=tc.cityid where tc.cityname not in('chennai','bangalore','hyderabed');

/*15. Whose name does not start with m And v display the employee name and id with ascending
order*/

select emp_no,concat(emp_firstname,emp_lastname) "name" from tblEmployee where emp_firstname


not like 'K%' and emp_firstname not like 'S%'

/**16. Who has more than 5years experience give 10000 commition*/

select * from tblEmployee where period_diff(extract(month from now()),extract(month from


hiredate))/12 <1

/*17. Select history of project for each employee name and id and Projectname */

select tph.projectno,tph.startdate,tph.enddate,concat(emp_firstname,emp_lastname) "NAME"


,emp_no,tp.project_name from tblEmployee temp

left outer join tblProjectHistory tph on temp.emp_no=tph.empno

left outer join tblProject tp on tph.projectno=tp.project_no

/*18. Find Address of employee from tamilnadu*/

select emp_no,concat(emp_firstname,emp_lastname)
"NAME",tcl.location_id,tcl.location_name,tcl.address1,tcl.address2,tcl.pin,tcl.cityid from tblEmployee
temp

join tblCompanyLocation tcl on temp.comp_locationid=tcl.location_id

join tblCity tc on tcl.cityid=tc.cityid where tc.statename like 'Tamilnadu'

/*19. Find the name of all employee whose commision is greater than the averge commision*/
select concat(emp_firstname,emp_lastname) "NAME" from tblEmployee where comm >(select
avg(comm) from tblEmployee)

/*20. Display the all employee name who are not working in siruseri/chennai*/

select concat(emp_firstname,emp_lastname) "NAME" from tblEmployee temp

join tblCompanyLocation tcl on temp.comp_locationid=tcl.location_id

where location_name not like 'Chennai'

select * from tblEmployee

Você também pode gostar