Last answered:

10 May 2023

Posted on:

04 May 2023

0

Resolved: why this code is not valid

use employees;

create view average_salaryy as
select  avg(s.salary) as total_Salary
from  dept_manager d
join salaries s on d.emp_no = s.emp_no
where salary = (select sum(s.salary) from salaries);


1 answers ( 1 marked as helpful)
Instructor
Posted on:

10 May 2023

0

Hi Abdelrahman!
Thanks for reaching out.


You do not need to assign the sum of the salaries. You need to simply join the tables and use the AVG() aggregate function.

Please, use the following code:

CREATE VIEW average_salaryy AS
    SELECT 
        AVG(s.salary) AS total_Salary
    FROM
        dept_manager d
            JOIN
        salaries s ON d.emp_no = s.emp_no;


Hope this helps.
Best,
Tsvetelin

Submit an answer