Dbms 5th Program
Dbms 5th Program
DNAME VARCHAR(20),
MGR_SSN VARCHAR(20),
MGR_START_DATE DATE);
DESC DEPARTMENT;
----------------------------------
NAME VARCHAR(20),
ADDRESS VARCHAR(20),
SEX CHAR(1),
SALARY INTEGER,
SUPERSSN VARCHAR(20),
DNO VARCHAR(20),
DESC EMPLOYEE;
----------------------------------
----------------------------------
--Create Table DLOCATION with PRIMARY KEY as DNO and DLOC and FOREIGN KEY DNO referring
DEPARTMENT table
(DLOC VARCHAR(20),
DNO VARCHAR(20),
DESC DLOCATION;
----------------------------------
--Create Table PROJECT with PRIMARY KEY as PNO and FOREIGN KEY DNO referring DEPARTMENT
table
PNAME VARCHAR(20),
PLOCATION VARCHAR(20),
DNO VARCHAR(20),
DESC PROJECT;
----------------------------------
--Create Table WORKS_ON with PRIMARY KEY as PNO and SSN and FOREIGN KEY SSN and PNO
referring EMPLOYEE and PROJECT table
(HOURS INTEGER,
SSN VARCHAR(20),
PNO INTEGER,
DESC WORKS_ON;
----------------------------------
----------------------------------
----------------------------------
SUPERSSN=NULL, DNO='3'
WHERE SSN='ABC01';
SUPERSSN='ABC03', DNO='5'
WHERE SSN='ABC02';
SUPERSSN='ABC04', DNO='5'
WHERE SSN='ABC03';
SUPERSSN='ABC06', DNO='5'
WHERE SSN='ABC04';
DNO='5', SUPERSSN='ABC06'
WHERE SSN='ABC05';
DNO='5', SUPERSSN='ABC07'
WHERE SSN='ABC06';
DNO='5', SUPERSSN=NULL
WHERE SSN='ABC07';
DNO='1', SUPERSSN='ABC09'
WHERE SSN='ABC08';
WHERE SSN='ABC09';
DNO='4', SUPERSSN=NULL
WHERE SSN='ABC10';
DNO='2', SUPERSSN=NULL
WHERE SSN='ABC11';
-------------------------------
--------------------------------
------------------------------
WHERE E.DNO=D.DNO
AND D.MGR_SSN=E.SSN
UNION
WHERE P1.PNO=W.PNO
AND E1.SSN=W.SSN
--Show the resulting salaries if every employee working on the ‘IoT’ project is given a 10 percent
raise.
WHERE E.SSN=W.SSN
AND W.PNO=P.PNO
AND P.PNAME='IOT';
--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
WHERE E.DNO=D.DNO
AND D.DNAME='ACCOUNTS';
--Retrieve the name of each employee who works on all the projects controlled by department
number 5 (use NOT EXISTS operator).
SELECT E.NAME
FROM EMPLOYEE E
WHERE NOT EXISTS(SELECT PNO FROM PROJECT WHERE DNO='5' AND PNO NOT IN (SELECT
WHERE E.SSN=SSN));
--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.
WHERE D.DNO=E.DNO
FROM EMPLOYEE E1
GROUP BY E1.DNO
HAVING COUNT(*)>5)
GROUP BY D.DNO;