-
Notifications
You must be signed in to change notification settings - Fork 0
/
GROUP BY_ORDER BY examples
68 lines (54 loc) · 1.51 KB
/
GROUP BY_ORDER BY examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Filtering Rockbuster Data
-- Customeer team, inventory team, and management board sent list of questions to answer
-- List of films that contain the word Uptown in any position
SELECT film_id,
title,
description
FROM film
WHERE title LIKE '%Uptown%'
GROUP BY film_id
ORDER BY title;
-- List of films with lengths more than 120 minutes and rental rate more than 2.99
SELECT film_id,
title,
description,
length,
rental_rate
FROM film
WHERE length >120 AND rental_rate >2.99
ORDER BY title;
-- List of films with a rental duration between 3 and 7 days (not inclusive)
SELECT film_id,
title,
description,
rental_duration
FROM film
WHERE rental_duration BETWEEN 4 AND 6
ORDER BY rental_duration, title;
-- List of films with replacement cost less than 14.99
SELECT film_id,
title,
description,
replacement_cost
FROM film
WHERE rental_rate <14.99
ORDER BY replacement_cost, title;
-- Films with movie ratings either PG or G
SELECT film_id,
title,
description,
rating
FROM film
WHERE rating = 'PG' OR rating = 'G'
ORDER BY rating, title;
-- Inventory team wants more information about movies that are PG or G
-- Including: count of movies, average rental rate, max and min rental durations
SELECT rating,
COUNT(film_id) AS "count of movies",
AVG(rental_rate)::NUMERIC(10,2) AS "average movie rental rate",
MAX(rental_duration) AS "maximum rental duration",
MIN(rental_duration) AS "minimum rental_duration"
FROM film
WHERE rating = 'PG' OR rating = 'G'
GROUP BY rating;
-- End of client requests