简体   繁体   中英

Query, Find the actor who has participated the most movies as "Principal Actor"

I have these 2 tables:

  1. movies:
movie_id movie_name
1 Name1
2 Name2
3 Name3
  1. people:
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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM