WEEK 6 arsh
WEEK 6 arsh
(JOINS)
DEPARTMENT TABLE(D) STAFF TABLE (S)
1.For all the staff members assigned to the existing departments, select all information about the staff members and
their respective departments.
2. Display the name salary, department identifier, and building and room location for every staff member assigned to
an existing department whose yearly salary exceeds $1000.
3. For every course with a lab fee over $175, display the course name, lab fee, and faculty number of the chairperson
responsible for the course. Display the output by course name in ascending sequence.
5. Display the building and room of any academic department which employs a staff member whose title begins with
“EVANGLIST”.
SELECT DISTINCT D.DBLD, D.DROOM FROM STAFF S
6. For each department described in the DEPARTMENT table which employs at least one staff member, display the
department identifier followed by the number of staff members assigned to the department.
SELECT S.DEPT, COUNT(*) AS Staff_Count
FROM STAFF S
GROUP BY S.DEPT;
7. For any course which has a staff member available to tutor students, display its number, the names and titles of
the staff members who ca serve as a tutor for the course, and their respective building and room locations. Sort the
output by staff member name within course number.
9. For each department referenced in the STAFF table, we would like to form a committee composed of two staff
members from the department. For each possible pair of staff members, display the department identifier followed
by the names of two staff members. The result should contain a row for every possible pair of staff members.
10. Refine the previous example query. For each department identifier referenced at least twice in the STAFF table,
display a row for each possible combination of distinct staff member names. The row should contain the department
identifier followed by staff member names.
SELECT S1.DEPT, S1.ENAME AS Staff1, S2.ENAME AS Staff2 FROM STAFF S1
WHERE S1.DEPT IN (SELECT DEPT FROM STAFF GROUP BY DEPT HAVING COUNT(*) >= 2);
11. Assume we would like to compare the salary of every staff member with every course lab fee. Whenever the
salary is less than the lab fee, display the staff member name and salary followed by the corresponding course name
and lab fee.
12. Assume that the dean is considering moving the administrative office of the management department. The
intention is to combine its administrative facilities with those of another department which is located in the same
building (which is unknown to the dean). To evaluate all possible options, display all information about the
management department followed by all information about any department which is located in the same building.
SELECT *FROM DEPARTMENT WHERE DBLD = (SELECT DBLD FROM DEPARTMENT WHERE DEPT = 'MGT');