0% found this document useful (0 votes)
2 views

WEEK 6 arsh

The document contains SQL queries for various operations involving STAFF and DEPARTMENT tables. It includes selecting staff information based on salary, course lab fees, and department assignments, as well as displaying combinations of staff members within departments. Additionally, it covers cross joins and comparisons between staff salaries and course lab fees.

Uploaded by

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

WEEK 6 arsh

The document contains SQL queries for various operations involving STAFF and DEPARTMENT tables. It includes selecting staff information based on salary, course lab fees, and department assignments, as well as displaying combinations of staff members within departments. Additionally, it covers cross joins and comparisons between staff salaries and course lab fees.

Uploaded by

talaganineeraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

WEEK -6

(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.

SELECT S.*, D.* FROM STAFF S

JOIN DEPARTMENT D ON S.DEPT = D.DEPT;

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.

SELECT S.ENAME, S.ESALARY, S.DEPT, D.DBLD, D.DROOM FROM STAFF S

JOIN DEPARTMENT D ON S.DEPT = D.DEPT WHERE S.ESALARY > 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.

SELECT t.cname, t.clabfee,t.dchfno FROM t

WHERE t.clabfee > 175 ORDER BY t.cname ASC;


4. Display the name and title of every staff member who works in the humanities building.

SELECT S.ENAME,S.ETITLE FROM STAFF S

JOIN DEPARTMENT D ON S.DEPT=D.DEPT WHERE D.DBLD='HU';

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

JOIN DEPARTMENT D ON S.DEPT = D.DEPT WHERE S.ETITLE LIKE 'EVANGLIST%';

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

WHERE S.DEPT IS NOT NULL

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.

SELECT x.cname, S.ENAME, S.ETITLE, D.DBLD, D.DROOM FROM t x

JOIN STAFF S ON S.ETITLE = 'LAB ASSIST'

JOIN DEPARTMENT D ON x.cdept = D.DEPT

ORDER BY S.ENAME, x.cname;


8. Form the cross product of the STAFF table and the DEPARTMENT table.

SELECT * FROM STAFF

CROSS JOIN DEPARTMENT;

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

JOIN STAFF S2 ON S1.DEPT = S2.DEPT AND S1.ENAME < S2.ENAME

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.

SELECT S.ENAME, S.ESALARY, x.cname, x.clabfee FROM STAFF S

JOIN t x ON S.ESALARY < x.clabfee;

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');

You might also like