【发布时间】:2018-03-26 03:18:53
【问题描述】:
问题:
编写一个 SQL 查询来检索重复的租金,其中相同的 客户不止一次租用同一部电影。如果客户多次租用同一部电影,则输出应仅显示此(客户姓名、电影名称)组合一次
有3个表:
- 客户表:(id、name、country、created_date)
- 电影表:(id, title, duration, release_year)
- 租借表:(id, customer_id, movie_id)
我目前有:
select customer.name, movie.title
from ((rental inner join customer on rental.customer_id = customer.id) inner join movie on rental.movie_id = movie.id)
group by customer.name, movie.title
having count(*) > 1;
但这是不正确的 - 有什么想法吗?
【问题讨论】:
-
在得到答案后,请勿编辑您的问题以删除其实质内容。 SO 问题不仅针对您,还针对整个社区。span>