I have these 2 tables:
movie_id | movie_name |
---|---|
1 | Name1 |
2 | Name2 |
3 | Name3 |
movie_id | person_name | role |
---|---|---|
1 | name1 | producer |
2 | name2 | principal actor |
3 | name3 | director |
Each movie goes with 1 principal actor but this actor can also go as principal actor to a lot of movies, so, I want to find the person that played the most movies as principal actor, I want an output like this:
movie_name | person_name | role |
---|---|---|
movie1 | name | principal actor |
movie2 | name | principal actor |
movie3 | name | principal actor |
or maybe one like this:
person_name | count (as principal actor) |
---|---|
name | 5 |
So far I've tried a subquery but I'm still a beginner and get many errors
You need to decide what the expected answer to your question is, your second choice would simply be
select person_name, Count(*) as PrincipleActor
from People
where role='principal actor'
group by person_name
order by PrincipleActor desc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.