DOC PREVIEW
UT Dallas CS 6360 - Midterm-1-Review

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

COMPLEX SQL – Answers to Assignment 2 Question 1 a. For each department whose average employee salary is more than $30,000, retrieve the department name and the number of employees working for that department. SELECT DNAME, COUNT (*) FROM DEPARTMENT, EMPLOYEE WHERE DNUMBER=DNO GROUP BY DNAME HAVING AVG (SALARY) > 30000 b. Suppose we want the number of male employees in each department making more than 30000 in average. SELECT DNAME, COUNT (*) FROM DEPARTMENT, EMPLOYEE WHERE DNUMBER=DNO AND GENDER='M' AND DNO IN (SELECT DNO FROM EMPLOYEE GROUP BY DNO HAVING AVG (SALARY) > 30000 ) GROUP BY DNAME c. Retrieve the names of all employees who work in the department that has the employee with the highest salary among all employees. SELECT Fname, Lname FROM EMPLOYEE WHERE Dno = ( SELECT Dno FROM EMPLOYEE WHERE Salary = ( SELECT MAX(Salary) FROM EMPLOYEE) ) d. Retrieve the names of employees who make at least $10,000 more than the employee who is paid the least in the company. SELECT Fname, Lname FROM EMPLOYEE WHERE Salary >= 10000 + ( SELECT MIN(Salary) FROM EMPLOYEE) e. Retrieve the names of employees who is making least in their departments and have more than one dependent. SELECT Fname, Lname FROM EMPLOYEE E WHERE Salary = (SELECT MIN(Salary) FROM Employee E2 WHERE E.Dno=E2.Dno)AND (Select Count(*) FROM Dependent D WHERE E.Ssn=D.Essn) > 1 Question 2 a. A view that has the department name, manager name and manager salary for every department. CREATE VIEW V1 AS SELECT Dname, Fname, Lname, Salary FROM Department, Employee WHERE D. Mgrssn=E.Ssn b. A view that has the department name, its manager's name, number of employees working in that department, and the number of projects controlled by that department (for each department). CREATE VIEW V2 AS SELECT Dname, Fname, Lname, (SELECT COUNT(*) FROM Employee E1 WHERE E1.Dno=D.Dno) AS Num_Employees, (SELECT COUNT(*) FROM PROJECT P WHERE P.Dno=D.Dno) AS Num_Projects FROM Department D, Employee E WHERE D.Mgrssn=E.Ssn c. A view that has the project name, controlling department name, number of employees working on the project, and the total hours per week they work on the project (for each project). CREATE VIEW V3 AS SELECT Pname, Dname, (SELECT COUNT(Ssn) FROM WORKS_ON W1 WHERE W1.Pno=P.Pno) AS Num_Employees, (SELECT SUM(Hours) FROM WORKS_ON W2 WHERE W2.Pno=P.Pno) AS Total_Hours FROM Project P, Department D WHERE P.Dno=D.Dno d. A view that has the project name, controlling department name, number of employees, and total hours worked per week on the project for each project with more than one employee working on it. CREATE VIEW V4 ASSELECT Pname, Dname, (SELECT COUNT(Ssn) FROM WORKS_ON W1 WHERE W1.Pno=P.Pno) AS Num_Employees, (SELECT SUM(Hours) FROM WORKS_ON W2 WHERE W2.Pno=P.Pno) AS Total_Hours FROM Project P, Department D WHERE P.Dno=D.Dno AND (SELECT COUNT(Ssn) FROM WORKS_ON W3 WHERE W3.Pno=P.Pno) > 1 OR CREATE VIEW V4 AS SELECT Pname, Dname, (SELECT COUNT(Ssn) FROM WORKS_ON W1 WHERE W1.Pno=P.Pno) AS Num_Employees, (SELECT SUM(Hours) FROM WORKS_ON W2 WHERE W2.Pno=P.Pno) AS Total_Hours FROM Project P, Department D WHERE P.Dno=D.Dno AND P.Pno IN (SELECT Pno FROM WORKS_ON GROUP BY Pno HAVING Count(*) > 1) e. A view that has the employee name, employee salary, department that the employee works in, department manager name, manager salary, and average salary for the department. CREATE VIEW V5 AS SELECT Dname, E.Fname, E. Lname, E.Salary, M. Fname, M.Lname, M.Salary, (SELECT AVG(Salary) FROM Employee E1 WHERE E1.Dno=E.DNo) AS Avg_Dept_Salary FROM Employee E, Department D, Employee M WHERE E.Dno=D.Dno AND D.Mgrssn=M.Ssn *** Employees who have two or more dependents: SELECT Lname, Fname FROM Employee WHERE (SELECT COUNT(*) FROM Dependent WHERE Essn=Ssn) >= 2 RELATIONAL ALGEBRA 1. Retrieve the name and address of all employees who work for the “Research”department.2. Retrieve the names of employees who have no dependents 3. List the names of managers who have at least one dependent. Exercises 6.16. d) For each project, list the project name and the total hours per week (by all employees) spent on that project. PROJ_HOURS(PNO,TOT_HRS) <-- PNO f SUM HOURS (WORKS_ON) RESULT <-- P PNAME,TOT_HRS ( (PROJ_HOURS) J (PNO),(PNUMBER) (PROJECT) )Exercises 6.16 (g) For each department, retrieve the department name, and the average salary of employees working in that department. DEPT_AVG_SALS(DNUMBER,AVG_SAL) <-- DNO f AVG SALARY (EMPLOYEE) RESULT <-- P DNUMBER,AVG_SAL ( DEPT_AVG_SALS * DEPARTMENT ) Exercises 6.16 (h) Retrieve the average salary of all female employees. RESULT(AVG_F_SAL) <-- f AVG SALARY ( s GENDER='F' (EMPLOYEE)


View Full Document

UT Dallas CS 6360 - Midterm-1-Review

Documents in this Course
Ch22(1)

Ch22(1)

44 pages

Ch21

Ch21

38 pages

Ch19

Ch19

46 pages

Ch18

Ch18

25 pages

Ch17

Ch17

21 pages

Ch15

Ch15

42 pages

Ch09

Ch09

42 pages

Ch05

Ch05

34 pages

Ch22

Ch22

45 pages

Ch21

Ch21

38 pages

Ch19

Ch19

48 pages

Ch18

Ch18

24 pages

Ch17

Ch17

22 pages

Ch16

Ch16

17 pages

Ch15

Ch15

42 pages

Ch09

Ch09

42 pages

Ch08

Ch08

39 pages

Ch07

Ch07

34 pages

Ch06

Ch06

43 pages

Ch05

Ch05

34 pages

Ch04

Ch04

39 pages

Ch03(2)

Ch03(2)

36 pages

Ch02

Ch02

33 pages

Ch08

Ch08

28 pages

Ch07

Ch07

31 pages

Ch06

Ch06

43 pages

Ch05

Ch05

39 pages

Ch04(1)

Ch04(1)

39 pages

Ch03(1)

Ch03(1)

38 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch24

Ch24

36 pages

Ch21

Ch21

54 pages

Ch19

Ch19

48 pages

Ch18

Ch18

24 pages

Ch17

Ch17

22 pages

Ch03(1)

Ch03(1)

38 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch24

Ch24

36 pages

Ch21

Ch21

54 pages

Ch19

Ch19

48 pages

Ch18

Ch18

24 pages

Ch17

Ch17

22 pages

Ch08

Ch08

28 pages

Ch07

Ch07

31 pages

Ch06

Ch06

43 pages

Ch05

Ch05

39 pages

Ch04(1)

Ch04(1)

39 pages

Ch08

Ch08

39 pages

Ch07

Ch07

40 pages

Ch06

Ch06

47 pages

Ch05

Ch05

41 pages

Ch04

Ch04

43 pages

Ch03

Ch03

41 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch18

Ch18

24 pages

Ch08

Ch08

39 pages

Ch07

Ch07

40 pages

Ch06

Ch06

47 pages

Ch05

Ch05

41 pages

Ch04

Ch04

43 pages

Ch03

Ch03

41 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch18

Ch18

24 pages

Ch17

Ch17

25 pages

lab-manual

lab-manual

215 pages

Ch08

Ch08

39 pages

Ch07

Ch07

40 pages

Ch06

Ch06

47 pages

Ch05

Ch05

41 pages

Ch04

Ch04

43 pages

Ch03

Ch03

41 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch17

Ch17

25 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch18

Ch18

24 pages

Ch17

Ch17

25 pages

Ch08

Ch08

39 pages

Ch07

Ch07

40 pages

Ch06

Ch06

47 pages

Ch05

Ch05

41 pages

Ch04

Ch04

43 pages

Ch03

Ch03

41 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Ch04(1)

Ch04(1)

43 pages

Ch07

Ch07

40 pages

Ch03

Ch03

42 pages

Ch01

Ch01

36 pages

Ch02

Ch02

38 pages

Ch05

Ch05

41 pages

Ch06

Ch06

47 pages

Ch08

Ch08

39 pages

Ch17

Ch17

25 pages

Ch18

Ch18

24 pages

Ch09

Ch09

42 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch21

Ch21

54 pages

Ch19

Ch19

51 pages

Ch18

Ch18

24 pages

Ch17

Ch17

25 pages

Ch09

Ch09

42 pages

Ch08

Ch08

39 pages

Ch07

Ch07

40 pages

Ch06

Ch06

47 pages

Ch05

Ch05

41 pages

Ch04(1)

Ch04(1)

43 pages

Ch03

Ch03

42 pages

Ch02

Ch02

38 pages

Ch01

Ch01

36 pages

Load more
Download Midterm-1-Review
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Midterm-1-Review and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Midterm-1-Review 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?