0% found this document useful (0 votes)
22 views14 pages

P New

Exchange..

Uploaded by

priyamorajkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views14 pages

P New

Exchange..

Uploaded by

priyamorajkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

PRACTICAL NO.

EMPLOYEES TABLE:

Create table employees(

E_ID int primary key,

E_Name varchar (20) not null,

Job varchar (20) not null,

Hire_date date not null,

D_No int not null,

No_Of_Projecs int not null,

Phone_No int not null,

head_id int references employees);

Alter table employees

Modify E_Name char(30)

Alter table employees

Modify Job char(30)

desc employees

insert into employees values('1101','Vijay Pawar','Principal','03-july-1996','1','8','1234567890','1101');

insert into employees values('1102','N.P.Chawande','Prof.','21-March-1996','1','10','2466217891','1102');

insert into employees values('1105','Varsha Bhole','Prof.','19-July-2004','5','10','2365410258','1105');

insert into employees values('1106','Manasi Deore','Asst.Prof.','03-Aug-2004','1','7','1234567890','1106');

insert into employees values('1107','Supriya Joshi','Asst.Prof.','15-july-


2003','1','7','2345621789','1107','50000');

insert into employees values('1108','Shaila Deore','Asst.Prof.','07-Aug-2007','5','6','4562137892','1108');

insert into employees values('1109','Surekha Khot','Asst.Prof.','1-January-2007','5','6','9874563210','1109');

insert into employees values('1110','Rachna Patil','Asst.Prof.','19-July-2004','1','10','1234567894','1110');

insert into employees values('1104','Sachen Chaure','Asst.Prof.','2-May-2008','2','1','4563217890','1104');

select * from employees


DEPARTMENT TABLE:

Create table Department(

D_no int primary key,

D_name varchar(20) not null,

Location varchar(30));

desc Department

insert into Department values ('2','COMP','THIRD FLOOR')

insert into Department values ('3','EXTC','FOURTH FLOOR')

insert into Department values ('1','IT','FOURTH FLOOR')

insert into Department values ('4','MECH','FIFTH FLOOR')

insert into Department values ('5','ELECTRICAL','FIRST FLOOR')

select * from Department

PROJECTS TABLE:

Create table projects(

p_no varchar(4) check(p_no like 'P%'),

P_name char(40) not null,


E_ID int references employees,

Location varchar(30),

D_no int references department);

DESC PROJECTS

Alter table projects

Add P_Cost_Cr decimal(7,3);

insert into projects values('P1','BOI project','1106','Mumbai','1','1234.67');

insert into projects values('P1','BOI project','1105','Mumbai','1','1234.67');

insert into projects values('P1','BOI project','1109','Mumbai','1','1234.67');

insert into projects values('P102','Data Science','1104','Pune','1','345.9');

insert into projects values('P102','Data Science','1102','Pune','2','345.9');

insert into projects values('P102','Data Science','1108','Pune','2','345.9');

insert into projects values('P101','AI project','1106','Navi Mumbai','1','3235.9');

select * from projects

QUERIES:

SIMPLE QUERIES:

1] List the emp who are working for the dept 1 and 2 .

Select E_ID, E_Name

From employees

where D_no in (1,2);


2] List the emp who joined in the month of Aug.

Select E_Id, E_Name

From employees

Where Hire_date = '%Aug'

3] List the enames that are starting with ‘S’ and with five characters.

Select E_Name

From employees

Where E_Name like 'S%';

4] List the total information of Employee along with Dname and Loc of all the

emps working Under “EXTC ’ & ‘IT’ in the asc DeptNo.

Select *

From employees e, Department d

Where e.D_no=d.D_no

And d.D_name in('Extc','IT')

Order by d.D_no asc


5] Display all the details of all ‘Asst. Prof.’.

Select * from employees

Where Job = 'Asst.Prof.'

6] Display projects in descending order on P_cost

Select * from projects

order by P_Cost_Cr desc

7] Display Unique Jobs from Employee table (Use of Distinct Keyword).

Select distinct(Job)

From employees
desc projects

Alter table employees

Add Salary int;

insert into employees values('1111','Sandeep Matey','Ass.Prof.','31-july-


1990','2','6','9867543210','1111','50000')

select * from employees

UPDATE employees SET salary='120000' where E_Id='1101';

UPDATE employees SET salary='90000' where E_Id='1102';

UPDATE employees SET salary='80000' where E_Id='1105';

UPDATE employees SET salary='60000' where E_Id='1106';

UPDATE employees SET Job='Asst.Prof.' where E_Id='1111';

select * from employees


QUERIES ON AGGREGATE FUNCTION AND GROUP BY CLAUSE

AGGREGATE FUNCTION

1] Find the highest salary of the employee table.

Select max(Salary) as Max_Salary

From employees

2] Find the no of employees working for each department.

Select D_no, count(E_Id)

From employees

Group by D_no

3] Find the total annual salary for each job (distribute job wise) in previous

year.

Select Job, sum(Salary)

From employees

Where Hire_Date not like '%17'

Group by Job
4] List the names of the dept where more than 5 emps are working.

Select D_no, count(E_Id)

From employees

Group by D_no

Having count(E_Id)>=5

4] List the names of the dept where more than 5 emps are working.

Select D_no, count(E_Id)

From employees

Group by D_no

Having count(E_Id)<5

DELETE OPERATION

5] Delete records from employee table whose hiredate year ‘2003’.

Delete from employees

Where Hire_Date like '%03'


6. Rollback from the previous action.

Rollback

Select * from employees

Delete from employees

Where E_Name = 'Manasi%';

UPDATE

7] Update all location of the department as : Computer : Third, IT: Fifth,

EXTC: Second MECH: Ground Floor and otherwise sixth floor .

Update Department

SET location = case

When D_name='COMP' then 'THIRD FLOOR'

When D_name='IT' then 'FIFTH FLOOR'

When D_name='EXTC' then 'SECOND FLOOR'

When D_name='MECH' then 'GROUND FLOOR'

Else 'SIXTH FLOOR'

End
select * from Department

8] Change the Empname ‘Sachen’ to ‘Sachin’ or use employee id to set

correct field value.

Update employees

SET E_Name='Sachin Chaure'

Where E_Name like 'Sachen%'

8] Change the Empname ‘Sachen’ to ‘Sachin’ or use employee id to set

correct field value.

Update employees

Set E_Name='Sachin Chaure'

Where E_Id=1104

Select E_Name
from employees

CARTESIAN PRODUCT

1]Select * from employees, Department

2]Select * from employees, projects

3]Select * from employees, Department, projects

NATURAL JOIN

1]Select * from employees, projects

Where employees.E_Id= projects.E_Id

2] Select * from employees e, projects p, Department d

Where e.e_id=p.e_id and p.d_no=d.d_no

USING RENAME OPERATOR IN BOTH CLAUSE: SELECT AND FROM


Select e.E_Id, e.E_Name, p.E_Id, e.D_No Emp_Dept, p.p_name, p.location, p.D_no

Projects_Dept

from employees e, projects p

Where e.E_Id= p.E_Id

COMPLEX QUERIES

QUERIES FOR PRACTICE

Query1:- List the employee belong to ‘1’ department

select * from employees where D_no=1

Query2:- List the employees belong to it department

select * from employees e, Department d where e.D_no=d.D_no and D_name='IT';

Select e.E_ID, e.E_Name, e.D_no, d.D_no, d.D_Name

From employees e, Department d


Where e.D_no = d.D_no and D_Name='IT';

Query3: Find employee information for those working on project located at

Pune.

Select e.E_Id, e.E_Name, p.p_no, p.E_Id, p.p_name, p.location

From employees e, projects p

Where e.E_Id = p.E_Id

And p.location = 'Pune';

Query4: Find the project whose name start with Database.

Select p_no, p_name

From projects

Where p_name like 'Data%';

You might also like