简体   繁体   English

SQL 列出演员相同的字符不同的电影

[英]SQL List actors same char different films

在此处输入图像描述

List all pairs of actors that have played the same character in different films.列出所有在不同电影中扮演相同角色的演员对。

List all pairs of actors that have played the same character in films with the same name.列出所有在同名电影中扮演相同角色的演员对。

List all reoccurring characters in the database, that is, characters like James Bond that appear in multiple films with different names.列出数据库中所有重复出现的角色,即像詹姆斯邦德这样出现在多部不同名字的电影中的角色。

There are no ideas for these three queries The first one I think we can use subqueries这三个查询没有思路第一个我觉得可以用子查询

SELECT *
FROM film
WHERE(
  select COUNT(*) AS R,roles from film
  group by roles 
  HAVING R>=2
)

If I am understanding the questions correctly you should be able to use self joins to answer them如果我正确理解了这些问题,您应该能够使用自我连接来回答它们

Select a.Principal Star
from film a 
inner join film b on a.Film_No = b.Film_No
where a.Principal Star = b.Principal Star and a.roles = b.roles and a.Film titles <> b.Film titles

Question 1:问题一:

select principal_stars,roles,count(distinct film_titles) 
from film
  group by principal_stars,roles 
  HAVING count(distinct film_titles) >1;
  

Question 2:问题2:

select 
films
,principal_stars
,roles
,count(*)
from 
film 
group by films,principal_stars,roles
having count(*)>1

Question 3:问题 3:

select roles
,count(distinct film_titles)
from film
group by roles
having count(*)>1

Not sure if this is the same you're expecting.不确定这是否与您期望的相同。 if not please add some sample output and data as text.如果不是,请添加一些示例 output 和数据作为文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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