【变态难】找出每部电影和单部电影销售冠军之间的销售差,列出电影名,销售额差额
思路:这道题乍一看还挺唬人的,理清思路也挺快。我的想法就是先查询最高销量单部电影想减即可。
select (sum_sale - (b.Domestic_sales + b.International_sales)) as sale_diff,m.Title from (
// 子查询主要求筛选单部电影以及求销售总和
select count(1) as c,sum(Domestic_sales + International_sales) sum_sale
from Movies,Boxoffice
where Movies.id = Boxoffice.Movie_id
group by Director having c = 1 order by sum_sale desc limit 1
) t,Movies m,Boxoffice b
where m.id = b.Movie_id