Professional Documents
Culture Documents
*** 6.
SELECT EMPLOYEE.LNAME, EMPLOYEE.FNAME
FROM EMPLOYEE
WHERE (SELECT COUNT(*)
FROM WORKS_ON
WHERE EMPLOYEE.SSN = WORKS_ON.WSSN) >= 2;
*** 9. Give names of projects which have at least one part supplied by
Smith.
(> 1 solutions: in, exist, equal join)
*** 10. Give supplier names and total quantity of parts distributed by
each 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 in
Paris.
(> 1 solutions: in, exist, equal join)
*** 12. Give supplier number for each supplier who provides more than
100 red screws to project #3.
(> 1 solutions: in, exist, equal join)
* 15. Get the social security number of each employee who works
over 15 hours on at least one project.
* 16. Get the social security number & last name of each female
employee who works in department #4.
** 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 (not
project #) that he/she is working on.
(> 1 solutions: in, exists, equal join)
** 20. For each supervisor, retrieve his/her social security number, and
the maximun salary among those employees supervised by
him/her.
** 21. For each department, get its department # & an average salary
of 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, lname
from employee
where ssn in (select wssn
from works_on
where pno < 15 and hours >= 20);
OR
select fname, lname
from employee
where exists (select *
from works_on
where ssn = wssn and pno < 15
and hours >= 20);
OR
select fname, lname
from employee, works_on
where ssn = wssn and pno < 15 and hours >= 20;
** 23. Get the first & last names of employees who have at
least one son.
select lname
from employee
where not exists
(select *
from works_on
where wssn = ssn and pno = 1);
select lname
from employee
where ssn not in (select wssn
from works_on
where pno = 1);
select lname
from employee, works_on
where pno <> 1 and ssn = wssn;
** 25. For each employee, list the first and last name of his/her
dependent(s).
(> 1 solutions: in, exists, equal join)
SELECT DEPARTMENT.DNAME
FROM DEPARTMENT, DEPT_LOCATION
WHERE DEPARTMENT.DNUMBER = DEPT_LOCATION.DNUMBER
AND DLOCATION = 'HOUSTON';
** 27. Get first & last name of the manager in the Research
department. ( > 1 solutions: exists, in, equal join)
** 28. For each employee, list his/her ssn & names of projects that
he/she is working on.
(> 1 solutions: in, exists, equal join)
SELECT DNAME
FROM DEPARTMENT, PROJECT
WHERE DNUMBER = DNUM AND PNAME = 'REORGANIZATION';
** 30. For the 'Research' department, get its department number & last
names of its employees.
(> 1 solutions: in, exists, equal join)
** 31. Get first & last name of each employee who has a dependent
with the same first name as the employee.
( > 1 solutions: exists, in, equal join)
*** 32. Get department name & the average salary of all employees in
each department.
*** 33. Get the first & last names of all employees who work on the
'ProductZ' project over 5 hours per week.
(> 1 solutions: in, exists, equal join)
*** 34. Get department # for each department which has average
salary more than $30000.
select dno
from employee
group by dno
having avg(salary) > 30000;
*** 35. Get the first & last names of employees who have at
least one dependent born in 1967.
*** 36. Get deparment number who has at least one employee working
on project number 1 or 2 or 30.
select dno
from employee, works_on
where ssn = wssn and pno in (1, 2, 30);
select dno
from employee
where ssn in (select WSSN
from works_on
where pno in (1, 2, 30));
select dno
from employee
where exists (select *
from works_on
where ssn = WSSN and pno in (1, 2, 30));
select dnum
from project
where pnumber in (select pno
from works_on
where pno in (1, 2, 30));
*** 37. Get ssn & address of each employee who works with Jennifer
Wallace on the same project.
*** 38. Get the social security number of all employees who work on 3
or more projects.
select ssn
from employee
where (select count(*)
from works_on
where ssn = wssn) >= 3;
*** 39. Remove John Smith's spouse from the dependent list.
delete
FROM DEPENDENT
WHERE RELATIONSHIP = 'SPOUSE' AND
DEPSSN = (SELECT SSN
FROM EMPLOYEE
WHERE FNAME = 'JOHN' AND LNAME = 'SMITH');
*** 40. Decrease 5 hours per week from each project that Joyce English
works on.
update works_on
SET HOURS = HOURS - 5
WHERE WSSN = (SELECT SSN
FROM EMPLOYEE
WHERE FNAME = 'JOYCE'
AND LNAME = 'ENGLISH');
*** 41. Find social security number and last name of the employee who
has the highest salary in his/her department.
(> 1 solutions: exists, =)
**** 42. Get department name & birthday of each employee who
works in Houston. The list should be ordered by the
department & within each department ordered
chronologically by birthday.
**** 43. Retrieve the first and last names of employees who work in
Administration department and are supervised under James
Borg.
(> 1 solutions: equal join, in, =, exists)
Smith09-JAN-55
English 31-JUL-62
Wong 08-DEC-45
Narayan 15-SEP-52
Jabbar 29-MAR-59
Borg 10-NOV-27
(Due 12/10 44-48)
(Find the first & last names of employees who have at least one
child.)
Franklin Wong
John Smith
DIVIDEBY
(33344555, 123456789)
<==> DAUGHTER
SON
SPOUSE
<==> 123456789
453453453
III. Give the relational algebra syntax for the following English
descriptions. Use the data & tables on page 3.
(10 points each)
* 48. Get the social security number & last name of each employee
who works in department #5.
** 50. Get the social security number & the salary of each employee
who works in Houston.
Wrong
((dept_locations where dlocation = 'Houston')
join employee) [ssn, salary]
** 51. Get the last name & birthday of each employee who works for
30 hours per week or more on project #10.
*** 53. For each employee, list his/her ssn & names of projects that
he/she is working on.
*** 54. For the 'Research' department, get its department number & last
names of its employees.
*** 55. Get the social security number of each employee who has no
dependent.
(EMPLOYEE [SSN])
MINUS
(DEPENDENT RENAME ESSN AS SSN [SSN])
*** 56. Get the first & last names of employees who have at least one
children. Assume each child of an employee in this company is a
dependent of that employee.
RANGE OF EX IS EMPLOYEE
EX.ADDRESS, EX.BDATE WHERE EX.FNAME = 'Jennifer'
AND EX.MINIT = 'S'
AND EX.LNAME = 'Wallance'
RANGE OF EX IS EMPLOYEE
RANGE OF DX IS DEPARTMENT
* 59. R1(e, f, g, h, i, j)
e -----> j
h -----> i
[e, f, g] is a composite key.
non-loss decomposition:
* 60 R1(a, b, c, d, e)
a -----> c
b -----> e
c -----> d
[a, b] is a composite key.
non-loss decomposition:
* 61. R1(i, j, k, l)
k -----> i
[i, j] is a composite key.
* 2. R2(p, q, s, t, u)
s -----> t
u -----> q
p is a key.
non-loss decomposition:
R1'(s, t),key = s
R2'(u, q), key = u
R3"(p, s, u), key = p
* 62. R3(w, x, y, z)
[x, z] is a composite key.
* 63. R4(m, n, o, p, q)
m, n are 2 keys, & [o, p] is a composite key.
BCNF because all determinents (m, n & [o, p]) are keys.
* 64. R3(m, n)
m -----> n
n -----> m
BCNF
* 65. R5(a, b, c, d, e, f)
c -----> a
c -----> f
d -----> b
[c, d] is a composite key.
* 66. R6(a, b, c, d, e)
[b, c] -----> a
[b, c] -----> d
[b, c] -----> e
d -----> e
a is a key.
* 67. R2(x, y, z)
z -----> y
x is a key.
R(a,b,c,d,e)
e-----> c
[a,c] is a composite key.
Ans:
C.K [a,c] , [a.e]
BCNF since every determinat is key.