Modul3-4-queries
Modul3-4-queries
( Fname Char(15),
Minit Char(15),
Lname Char(15),
Ssn Number(5),
Bdate date,
Address char(15),
Gender char(2),
Salary number(5),
Super_ssn number(5),
Dno number(3),
PRIMARY KEY (Ssn));
q2:SELECT Pnumber, Dnum, Lname, Address, Bdate from PROJECT, DEPARTMENT, EMPLOYEE6
where Dnum = Dnumber AND Mgr_ssn = Ssn AND
Plocation = 'Mumbai';
10:Retrieve the name of each employee who works on all the projects controlled by
department number 2
11: Retrieve the Social Security numbers of all employees who work on project
numbers 1, 2, or 3
SELECT DISTINCT Essn FROM WORKS_ON WHERE Pno IN (1, 2, 3)
12:retrieve the last name of each employee and his or her supervisor while renaming
the resulting attribute names as Employee_name and Supervisor_name.
13:Write the sql query to retrieves the name and address of every employee who
works for the ‘Research’ department using JOIN .
14:Join Qieries
select * from employee6 right join department on ssn=mgr_ssn;
15: SELECT FROM SUM (Salary), MAX (Salary), MIN (Salary), AVG (Salary) EMPLOYEE6;
19: select count(*) from employee6, department where DNO = DNUMBER AND DNAME =
'Research';
20:SELECT Lname, Fname FROM EMPLOYEE6 where (SELECT COUNT (*) FROM DEPENDENT WHERE
Ssn=Essn )>=1;
21:
For each department, retrieve the department number, the number of employees in the
department, and their average salary.
SELECT Dno, COUNT (*), AVG (Salary)
FROM EMPLOYEE6 GROUP BY Dno;
22:For each project, retrieve the project number, the project name, and the number
of employees who work on that project
SELECT pnumber, Pname, COUNT (*) FROM PROJECT, WORKS_ON where Pnumber = Pno GROUP
BY Pnumber, Pname;
23: For each project on which more than two employees work, retrieve the project
number, the project name, and the number of employees who work on
the project.
SELECT Pnumber, Pname, COUNT (*) FROM PROJECT, WORKS_ON WHERE Pnumber = Pno GROUP
BY Pnumber, Pname
HAVING COUNT (*) > 2;
24: For each project, retrieve the project number, the project name, and
the number of employees from department 5 who work on the project