MySQL - Using JOIN and WHERE to determine average hours

前端 未结 4 1216
死守一世寂寞
死守一世寂寞 2021-01-22 13:15

I am learning MySQL using a next.tech course that relies on the following schema:

My current task is to find the average number of hours worked on one specific

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 14:01

    The syntax of your SQL query seems to be the main problem behind the first error.

    you are doing SELECT-FROM-WHERE-JOIN, but the actual sequence should be SELECT-FROM-JOIN-WHERE.

    Your second query (which is returning a wrong value) has the correct syntax, which is why it returns something.

    Secondly, you should be comparing projects.id with project_employees.project_id, not project_employees.employee_id. Therefore, your query should be something like -

    SELECT AVG(hours) FROM project_employees
    JOIN  projects
    ON  project_employees.project_id = projects.id
    WHERE name = 'Washington Avenue Barber';
    

提交回复
热议问题