前述
知识点回顾:union all和union的区别
- Union :对两个结果集进行并集操作,不包括重复行,同时进行默认规则的排序;
- Union All :对两个结果集进行并集操作,包括重复行,不进行排序;
题目描述
leetcode 题目:1341. 电影评分
Code
sql
(
select name as results
from MovieRating MR
left join Users U
on MR.user_id = U.user_id
group by MR.user_id
order by count(*) desc, name asc
limit 1
)
union all
(
select title
from MovieRating MRR
left join Movies M
on MRR.movie_id = M.movie_id
where created_at between '2020-02-01' and '2020-02-29'
group by MRR.movie_id
order by avg(rating) desc, title asc
limit 1
)