How to fix error in SQL query

vitaminchik 486 Reputation points
2023-04-20T11:52:26.0233333+00:00

How to fix error in SQL query. User's image

User's image

User's image

SQL Server Other
{count} votes

Accepted answer
  1. Olaf Helper 47,436 Reputation points
    2023-04-20T12:08:41.1833333+00:00

    Where did I make a mistake?

    Nearly everywhere. If you want to use aggregation function, the in common we use a GROUP BY clause. Try it with

    SELECT A.actor_id, A.first_name, A.last_name, COUNT(*) AS CountFims
    FROM actor AS A
         LEFT JOIN
         film_actor AS F
            ON A.actor_id = F.actor_id
    GROUP BY A.actor_id, A.first_name, A.last_name
    HAVING COUNT(*) < 20 
    
    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Naomi Nosonovsky 8,431 Reputation points
    2023-04-20T14:29:24.8966667+00:00
    ;with cte as (select actor_id, count(film_id) as cntFilms from film_actor group by actor_Id having count(film_id) < 20)
    select a.* from Actor  a join cte on a.actor_Id = cte.Actor_ID
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.