DOC PREVIEW
UT Dallas CS 6385 - c157home_work1

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 16 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 16 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 16 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 16 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 16 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 16 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 157 EXERCISE KEY Database DB2 and DB1BI. Give the output of the following SQL query.(Due 11/29: 1-8)** 1. SELECT EMPLOYEE.SSN, EMPLOYEE.LNAME FROM DEPARTMENT, EMPLOYEE WHERE DEPARTMENT.DNAME = 'ADMINISTRATION' AND EMPLOYEE.DNO = DEPARTMENT.DNUMBER;** 2. SELECT EMPLOYEE.FNAME, EMPLOYEE.LNAME FROM EMPLOYEE WHERE EXISTS (SELECT * FROM WORKS_ON WHERE WORKS_ON.WSSN = EMPLOYEE.SSNAND WORKS_ON.PNO <> 1);** 3. SELECT EMPLOYEE.SSN, EMPLOYEE.LNAME, EMPLOYEE.BDATE FROM EMPLOYEE WHERE EMPLOYEE.ADDRESS LIKE '%BELLAIRE%';*** 4. SELECT EMPLOYEE.SSN, EMPLOYEE.FNAME, EMPLOYEE.LNAME FROM EMPLOYEE WHERE EXISTS (SELECT * FROM DEPENDENT WHERE EMPLOYEE.SSN =DEPENDENT.DEPSSN) AND EXISTS (SELECT * FROM DEPARTMENT WHERE EMPLOYEE.SSN = DEPARTMENT.MGRSSN);(delete) 5. SELECT EMPLOYEE.SSN, EMPLOYEE.FNAME, EMPLOYEE.LNAME FROM EMPLOYEE WHERE EXISTS (SELECT * FROM DEPENDENT WHERE EMPLOYEE.SSN = DEPENDENT.DEPSSN) AND EXISTS (SELECT * FROM DEPARTMENTWHERE EMPLOYEE.SSN = DEPARTMENT.MGRSSN);*** 6. SELECT EMPLOYEE.LNAME, EMPLOYEE.FNAME FROM EMPLOYEE WHERE (SELECT COUNT(*) FROM WORKS_ON WHERE EMPLOYEE.SSN = WORKS_ON.WSSN) >= 2; *** 7. SELECT LNAME, SALARY FROM EMPLOYEE ORDER BY SALARY DESC, LNAME ASC;*** 8. SELECT DEPARTMENT.DNAME, COUNT(*) FROM DEPARTMENT, EMPLOYEE WHERE DEPARTMENT.DNUMBER = EMPLOYEE.DNO GROUP BY DEPARTMENT.DNAME HAVING COUNT(*) > 2;(please create your own table) II. Give SQL syntax for the following English descriptions. (USE DB1b). *** 9. Give names of projects which have at least one part supplied bySmith.(> 1 solutions: in, exist, equal join)*** 10. Give supplier names and total quantity of parts distributed byeach supplier. List the names in alphabetic order.*** 3. Retrieve name and color of each part supplied to the project'Terminal'.(> 1 solutions: in, exist, equal join)*** 11. Get supplier names who provide parts to a project located inParis.(> 1 solutions: in, exist, equal join)*** 12. Give supplier number for each supplier who provides more than100 red screws to project #3.(> 1 solutions: in, exist, equal join)II. Give SQL syntax for the following English descriptions.(Due 11/30 13-15) * 13. Get name of each project located in Stafford.* 14. Get project location of the 'ProductX'.* 15. Get the social security number of each employee who worksover 15 hours on at least one project.(Due 12/1 15-18)* 16. Get the social security number & last name of each femaleemployee who works in department #4.* 17. Increase the salary of each employee working in department #5by 8.5%.** 18. For each employee, get his/her social security number and total# of hours he/she works.(Due 12/2 18-21)** 19. For each employee, list his/her ssn & number of projects (notproject #) that he/she is working on.(> 1 solutions: in, exists, equal join)** 20. For each supervisor, retrieve his/her social security number, andthe maximun salary among those employees supervised byhim/her.** 21. For each department, get its department # & an average salaryof all employee working there.(Due 12/3 21-24) ** 22. Get the first & last names of employees who work for 20 hours per week or more on project number less than 15.(use “in” “exists” join)select fname, lnamefrom employeewhere ssn in (select wssn from works_on where pno < 15 and hours >= 20);ORselect fname, lnamefrom employeewhere exists (select * from works_on where ssn = wssn and pno < 15 and hours >= 20);ORselect fname, lnamefrom employee, works_onwhere ssn = wssn and pno < 15 and hours >= 20;** 23. Get the first & last names of employees who have at least one son.SELECT FNAME, LNAMEFROM EMPLOYEE, DEPENDENTWHERE SSN = DEPSSN AND DEPENDENT.RELATIONSHIP = 'SON';SELECT FNAME, LNAMEFROM EMPLOYEEWHERE SSN IN (SELECT DEPSSN FROM DEPENDENT WHERE RELATIONSHIP = 'SON');SELECT FNAME, LNAMEFROM EMPLOYEEWHERE EXISTS (SELECT * FROM DEPENDENT WHERE SSN = DEPSSN AND RELATIONSHIP = 'SON');** 24. Get last name of each employee who does not work on project #1. Assume every employee works on at leastone project.select lnamefrom employeewhere not exists(select * from works_on where wssn = ssn and pno = 1);select lnamefrom employeewhere ssn not in (select wssn from works_on where pno = 1);select lnamefrom employee, works_onwhere pno <> 1 and ssn = wssn;(Due 12/4 24-27)** 25. For each employee, list the first and last name of his/herdependent(s).(> 1 solutions: in, exists, equal join)select dependent_name, lnamefrom employee, dependentwhere ssn = depssn;** 26. Get name of each department which has a location in Houston. (> 1 solutions: exists, in, equal join)SELECT DEPARTMENT.DNAMEFROM DEPARTMENT, DEPT_LOCATIONWHERE DEPARTMENT.DNUMBER = DEPT_LOCATION.DNUMBERAND DLOCATION = 'HOUSTON';** 27. Get first & last name of the manager in the Researchdepartment. ( > 1 solutions: exists, in, equal join)SELECT FNAME, LNAMEFROMEMPLOYEE, DEPARTMENTWHERE SSN = MGRSSN AND DNAME = 'RESEARCH';(Due 12/5 28-31)** 28. For each employee, list his/her ssn & names of projects thathe/she is working on.(> 1 solutions: in, exists, equal join)select wssn, pnamefrom works_on, projectwhere pno = pnumber;** 29. Get department name of the 'Reorganization' project.(> 1 solutions: in, exists, equal join)SELECT DNAMEFROM DEPARTMENT, PROJECTWHERE DNUMBER = DNUM AND PNAME = 'REORGANIZATION';** 30. For the 'Research' department, get its department number & lastnames of its employees.(> 1 solutions: in, exists, equal join)SELECT DNO, LNAMEFROM DEPARTMENT, EMPLOYEEWHERE DNUMBER = DNO AND DNAME = 'RESEARCH';(Due 12/6 31-34)** 31. Get first & last name of each employee who has a dependentwith the same first name as the employee.( > 1 solutions: exists, in, equal join)select fname, lnamefrom employeewhere ssn in (select depssn from dependent where depssn = ssn and fname = dependent_name);select fname, lnamefrom employee, dependentwhere ssn = depssn and fname = dependent_name;*** 32. Get department name & the average salary of all employees ineach department.select dname, avg(salary)from department, employeewhere dnumber = dnogroup by dname;*** 33. Get the first & last


View Full Document

UT Dallas CS 6385 - c157home_work1

Documents in this Course
assn1

assn1

2 pages

38rel2

38rel2

5 pages

Report

Report

3 pages

networks

networks

18 pages

lp2

lp2

44 pages

lp2 (2)

lp2 (2)

27 pages

lp1(1)

lp1(1)

21 pages

integer1

integer1

50 pages

FrankR2

FrankR2

3 pages

duality

duality

28 pages

CMST

CMST

44 pages

hw4

hw4

3 pages

for 1

for 1

11 pages

ENCh02

ENCh02

33 pages

pree

pree

2 pages

new  3

new 3

2 pages

new  2

new 2

2 pages

hw4a

hw4a

2 pages

T2_Sol

T2_Sol

4 pages

ISM3

ISM3

8 pages

hw4_sol

hw4_sol

6 pages

Elm04_06

Elm04_06

11 pages

atn proj2

atn proj2

20 pages

12CUT1

12CUT1

8 pages

09Ford

09Ford

23 pages

08FLOW

08FLOW

6 pages

03LP_su

03LP_su

6 pages

40REL40

40REL40

5 pages

39rel3

39rel3

5 pages

38arel2

38arel2

5 pages

37REL1

37REL1

3 pages

24TABU

24TABU

3 pages

22DYNPR

22DYNPR

3 pages

21B&C

21B&C

2 pages

20BBEX0

20BBEX0

3 pages

19BB

19BB

5 pages

14CAPBUD0

14CAPBUD0

11 pages

35BRXCH

35BRXCH

2 pages

34COMB

34COMB

4 pages

32CAPAS

32CAPAS

4 pages

31QUEUE

31QUEUE

3 pages

Load more
Download c157home_work1
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 c157home_work1 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 c157home_work1 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?