SQL - COUNT and GROUP BY doubt

Asked

Viewed 31 times

-2

I have the following question:

Select the first name (first_name) and title of the film (film) of all(s) the actors/actors/actresses (actor) associated(s) with the movies of the (Category) comedy (Comedy) category (use IN or ANY).

So far I’ve got this:

SELECT first_name, title, COUNT(*)

FROM ACTOR a, CATEGORY c, FILM f, FILM_CATEGORY fc, FILM_ACTOR fa

WHERE a.actor_id = fa.actor_id

AND fa.film_id = c.name in (‘Comedy’)

GROUP BY c.name;

The problem is that it shows nothing. It claims loss in connection with SQL, but I know it is some error in the code, I tried several ways but I could not.

Picture of the diagram: Diagrma da questao

  • this is a simple problem and I believe that many OS users can answer the full query without problems, but since this is an exercise, I believe it is worth you to study how to solve instead of a user from here giving you the answer by hand, so seeing here you just need to know how JOIN and IN work in this exercise, I believe that only if you read about you will be able to answer and learn properly :) JOIN - https://www.w3schools.com/sql/sql_join.asp IN - https://www.w3schools.com/sql/sql_in.asp

1 answer

-4

Link to references: https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_in

INNER JOIN Customers  on Orders.CustomerID = Customers.CustomerID
WHERE Customers.Country  IN ('Brazil', 'Argentina', 'Portugal')
GROUP BY Customers.Country;

Your code:

SELECT first_name, title, COUNT(*)

FROM ACTOR a, CATEGORY c, FILM f, FILM_CATEGORY fc, FILM_ACTOR fa

WHERE a.actor_id = fa.actor_id

AND fa.film_id = c.name in (‘Comedy’)

GROUP BY c.name;

some notes.
the total COUNT(*) it is necessary?
here fa.film_id = c.name is comparing id to the category name, I believe that would be fa.film_id = c.categoria_id


SELECT first_name, title, **COUNT(*)**

FROM ACTOR a, CATEGORY c, FILM f, FILM_CATEGORY fc, FILM_ACTOR fa

WHERE a.actor_id = fa.actor_id

AND **fa.film_id = c.name** in (‘Comedy’)

GROUP BY c.name;
  • 1

    that answer does not answer the question...

  • I made the appropriate changes, but see only It runs, but returns me only a name and only a title, but this title, in this case this film, nor the category "Comedy" is. I have looked at the tables actors and movies, he would have to return me several actors and several films, which are related to "Comedy"

  • can put the data of the tables here to see

Browser other questions tagged

You are not signed in. Login or sign up in order to post.