Example 1: querying with
set functions
- Find the total salary and the
average salary of the
salary paid to
employees in the
"Research" department.
- Solution:
|
Example 1: querying with
set functions
Example 1: querying with
set functions
Example 2: querying with
set functions
- Find the fname and lname
of the employee
in the
Research department
that earns more than the
average salary in the
(whole) company
- Solution:
|
Example 2: querying with
set functions
Example 2: querying with
set functions
Example 2: querying with
set functions
Example 3: querying with
set functions
- Find the fname and lname
of the employee
in the
Research department
that earns more than the
average salary
within the
'Research' department
-
Solution:
|
Example 3: querying with
set functions
- Find the fname and lname
of the employee
in the
Research department
that earns more than the
average salary
within the
'Research' department
-
Wrong
solution:
SELECT fname, lname
FROM employee
WHERE salary > ( SELECT AVG(salary)
FROM employee, department
WHERE dno = dnumber
AND dname = 'Research' )
Problem:
The employee may not work in the Research dept
|
|
Example 2: querying with
set functions
Example 2: querying with
set functions
Example 2: querying with
set functions
- Find the fname and lname
of the employee
in the
Research department
that earns more than the
average salary
within the
'Research' department
(3)
Solution:
SELECT fname, lname
FROM employee
WHERE dno IN ( SELECT dnumber
FROM department
WHERE dname = 'Research' )
AND
salary > ( SELECT AVG(salary)
FROM employee, department
WHERE dno = dnumber
AND dname = 'Research' )
|
|
❮
❯