Skip to content

Commit e6653a4

Browse files
committed
Section 06 : Subqueries - part 02 - P 3 , 4
1 parent 370d008 commit e6653a4

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(SELECT u.name AS results
2+
FROM MovieRating AS mr
3+
LEFT JOIN Users AS u
4+
USING (user_id)
5+
GROUP BY user_id
6+
ORDER BY COUNT(movie_id) DESC, u.name ASC LIMIT 1)
7+
8+
UNION ALL
9+
10+
(SELECT m.title
11+
FROM MovieRating AS mr
12+
LEFT JOIN Movies AS m
13+
USING (movie_id)
14+
WHERE created_at BETWEEN '2020-02-01' AND '2020-02-29'
15+
GROUP BY movie_id
16+
ORDER BY AVG(rating) DESC, m.title ASC LIMIT 1)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SELECT
2+
a.visited_on,
3+
SUM(b.amount) AS amount,
4+
ROUND(SUM(b.amount)/7, 2) AS average_amount
5+
6+
FROM
7+
(SELECT DISTINCT visited_on FROM Customer) a
8+
JOIN Customer b ON DATEDIFF(a.visited_on, b.visited_on) BETWEEN 0 AND 6
9+
10+
GROUP BY a.visited_on
11+
HAVING a.visited_on >= MIN(b.visited_on) + 6

0 commit comments

Comments
 (0)