0% found this document useful (0 votes)
144 views3 pages

SQL Queries for CS Students

This document contains an assignment submission for a database course. It includes the schema for several database tables related to employees, departments, projects, and dependents. It then lists 4 SQL queries that are to be written using this schema. The queries include counting employees by department, filtering projects by employee count, filtering projects and employees by department number, and filtering departments and employees by salary threshold and employee count.

Uploaded by

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

SQL Queries for CS Students

This document contains an assignment submission for a database course. It includes the schema for several database tables related to employees, departments, projects, and dependents. It then lists 4 SQL queries that are to be written using this schema. The queries include counting employees by department, filtering projects by employee count, filtering projects and employees by department number, and filtering departments and employees by salary threshold and employee count.

Uploaded by

Obaid Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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)

You might also like