0% found this document useful (0 votes)
23 views21 pages

Company Database

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

Company Database

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

Company Database

create table employee


(
ssn varchar2(5),
name varchar2(15),
address varchar2(15),
sex varchar2(6),
salary int,
superssn varchar2(5),
dno varchar2(5),
primary key(ssn),
foreign key(superssn) references employee(ssn) on delete
cascade
);
create table department
(
dno varchar(5),
dname varchar(15),
mgrssn varchar(5),
mgrstartdate date,
primary key(dno),
foreign key(mgrssn) references employee(ssn)
on delete cascade
);
• alter table employee add constraint fk1 foreign
key(dno) references department(dno) on delete
cascade;
create table dlocation
(
dno varchar(5),
dloc varchar(15),
primary key (dno,dloc),
foreign key(dno) references department(dno) on
delete cascade
);
create table project
(
pno varchar(5),
pname varchar(10),
plocation varchar(10),
dno varchar(5),
primary key(pno),
foreign key(dno) references department(dno) on delete
cascade
);
create table works_on
(
ssn varchar(5),
pno varchar(5),
hours int,
primary key(ssn, pno),
foreign key(ssn) references employee(ssn) on delete cascade,
foreign key(pno) references project(pno) on delete cascade
);
1. Make a list of all project numbers for projects that involve
an employee whose last name is ‘Scott’, either as a worker
or as a manager of the department that controls the project.

select distinct pno


from project
where pno in
(select pno
from works_on w, employee e
where w.ssn = e.ssn and name like '%scott') or
pno in
(select pno
from project p, department d, employee e
where p.dno = d.dno and mgrssn = ssn and name like '%scott');
2*. Show the resulting salaries if every employee
working on the ‘IoT’ project is given a 10 percent
raise.
select e.name, e.salary*1.1 as new_salary
from employee e, works_on w
where e.ssn = w.ssn and
w.pno in
(select pno
from project
where pname ='iot');
2. Show the resulting salaries if every employee
working on the ‘IoT’ project is given a 10
percent raise.

select e.name, e.salary*1.1 as new_salary


from employee e, works_on w, project p
where pname ='iot'
and p.pno=w.pno
and w.ssn = e.ssn;
3*. Find the sum of the salaries of all employees of
the ‘Accounts’ department, as well as the maximum
salary, the minimum salary, and the average salary in
this department

select sum(salary), max(salary), min(salary),


avg(salary)
from (employee e join department d on d.dno =
e.dno)
where d.dname = 'data mining';
3. Find the sum of the salaries of all employees
of the ‘Accounts’ department, as well as the
maximum salary, the minimum salary, and the
average salary in this department

select sum(salary), max(salary), min(salary),


avg(salary)
from employee e ,department d
where d.dname = ‘accounts‘
and d.dno = e.dno;
4. Retrieve the name of each employee who works
on all the projects controlled by department
number 5 (use NOT EXISTS operator).

select name
from employee e
where not exists
((select pno from project where dno=2) minus
(select pno from works_on where ssn = e.ssn));
5. For each department that has more than five
employees, retrieve the department number and
the number of its employees who are making more
than Rs. 6,00,000.
select d.dno, count(*) as count
from department d,employee e
where d.dno= e.dno and salary >600000
and d.dno in
(select dno from employee
group by dno having count(*)>3)
group by d.dno;
select dno, count(*) as count
from employee
where salary >600000
and dno in
(select dno from employee
group by dno
having count(*)>5)
group by dno;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy