|
I will illustrate this technique with some examples
|
Solution:
The depedent relation: select * from dependent +-----------+-----------+------+-----------+--------------+ | essn | name | sex | bdate | relationship | +-----------+-----------+------+-----------+--------------+ | 333445555 | Alice | F | 05-APR-76 | DAUGHTER | | 333445555 | Theodore | M | 25-OCT-73 | SON | | 333445555 | Joy | F | 03-MAY-48 | SPOUSE | | 987654321 | Abner | M | 29-FEB-32 | SPOUSE | | 123456789 | Micheal | M | 01-JAN-78 | SON | | 123456789 | Alice | F | 31-DEC-78 | DAUGHTER | | 123456789 | Elizabeth | F | 05-MAY-57 | SPOUSE | +-----------+-----------+------+-----------+--------------+ |
Alternative solution using a sub-query:
Logic: select fname, lname from employee E where # { dependents of E } > 2> 2 We must re-write "count( select * )" in correct SQL syntax: select fname, lname from employee E where ( select count(*) from dependent where essn = E.ssn ) > 2 +--------+-------+ | fname | lname | +--------+-------+ | John | Smith | | Frankl | Wong | +--------+-------+ |
Comment:
|
|
Solution:
|
Alternative solution using a sub-query:
select fname, lname from employee E where sum(hours worked by employee E) < 40 |