Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

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 d.Dnumber AS dept_number, COUNT(e.ECNIC) AS total_employees,


AVG(e.Salary) AS avg_salary

FROM DEPARTMENT AS D

JOIN EMPLOYEE AS E ON E.Dno = D.Dnumber

GROUP BY D.Dnumber

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 P.Pnumber AS project_number, P.Pname AS project_name,


COUNT(W.ECNIC) AS total_employees
FROM project AS P
JOIN works_on AS W ON P.Pnumber = W.Pno
GROUP BY P.pno HAVING COUNT(W.ECNIC) > 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 P.Pnumber AS project_number, P.Pname AS
project_name,COUNT(W.ECNIC) AS dept5_employee
FROM project AS P
JOIN works_on AS W ON P.Pnumber = W.Pno employee AS E ON W.ECNIC =
E.ECNIC
WHERE E.Dno = 5
GROUP BY P.Pnumber

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 D.Dnumber AS dept_number, COUNT(e.ECNIC) AS E.Salary
FROM employee AS E
JOIN department AS D ON E.Dno = D.Dnumber AND E.Salary > 60000
AND D.Dnumber IN (SELECT D.Dnumber
FROM employee AS E
JOIN department AS D ON E.Dno = D.Dnumber
GROUP BY D.Dnumber
HAVING COUNT(E.ECNIC) > 5)

You might also like