UNIVERSITY OF ENGINEERING
AND TECHNOLOGY
(Mardan)
IDS Assignment # 5
Submittet to Sir Zafar Ali
Name Obaid Ullah
Subject ; IDS (Theory)
Semester ; 4th
Section ; “B”
Roll No ; 35
DEPARMENT OF COMPUTER SOFTWARE ENGINEERING
UNIVERSITY OF ENGINNERING AND TECHNOLOGY
(MARDAN)
For the given Relational Schema, Write SQL queries for the following
EMPLOYEE (Fname, Lname, ECNIC, BirthDate, Address, Sex, Salary, Super_cnic, Dno)
DEPARTMENT (Dname, Dnumber, Mgr_cnic, Mgr_start_date)
DEPT_LOCATIONS (Dnumber, Dlocation)
PROJECT (Pname, Pnumber, Plocation, Dnum)
WORKS_ON (ECNIC, Pno, Hours)
DEPENDENT (ECNIC, Dependent_name, Sex, date_of_birth, Relationship)
1)
SELECT [Link] AS dept_number, COUNT([Link]) AS total_employees,
AVG([Link]) AS avg_salary
FROM DEPARTMENT AS D
JOIN EMPLOYEE AS E ON [Link] = [Link]
GROUP BY [Link]
2) For each project on which more than two employees work, select the project
number, the project name and the number of employees who work on that
project.
SELECT [Link] AS project_number, [Link] AS project_name,
COUNT([Link]) AS total_employees
FROM project AS P
JOIN works_on AS W ON [Link] = [Link]
GROUP BY [Link] HAVING COUNT([Link]) > 2
3) For each project, select the project number, the project name and the number of
employees from department 5 who work on the project.
SELECT [Link] AS project_number, [Link] AS
project_name,COUNT([Link]) AS dept5_employee
FROM project AS P
JOIN works_on AS W ON [Link] = [Link] employee AS E ON [Link] =
[Link]
WHERE [Link] = 5
GROUP BY [Link]
4) For each department that has more than five employees, select the department
number and the number of its employees who are making more than
60,000(Threshold changed from 20000 to 60000).
SELECT [Link] AS dept_number, COUNT([Link]) AS [Link]
FROM employee AS E
JOIN department AS D ON [Link] = [Link] AND [Link] > 60000
AND [Link] IN (SELECT [Link]
FROM employee AS E
JOIN department AS D ON [Link] = [Link]
GROUP BY [Link]
HAVING COUNT([Link]) > 5)