-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_plays_flixbus.sql
More file actions
39 lines (32 loc) · 1.41 KB
/
sql_plays_flixbus.sql
File metadata and controls
39 lines (32 loc) · 1.41 KB
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
-------------------------------
-- CREATE TABLE plays (
-- id INTEGER NOT NULL,
-- title VARCHAR(40) NOT NULL,
-- writer VARCHAR(40) NOT NULL,
-- UNIQUE(id)
-- );
-- CREATE TABLE reservations (
-- id INTEGER NOT NULL,
-- play_id INTEGER NOT NULL,
-- number_of_tickets INTEGER NOT NULL,
-- theater VARCHAR(40) NOT NULL,
-- UNIQUE(id)
-- );
-------------------------------
-- INSERT INTO plays VALUES (109, "Queens and Kings of Madagascar", "Paul Sat");
-- INSERT INTO plays VALUES (123, "Merlin", "Lee Roy");
-- INSERT INTO plays VALUES (142, "Key of the tea", "Max Rogers");
-- INSERT INTO plays VALUES (144, "ROMEance Comedy", "Bohring Ashell");
-- INSERT INTO plays VALUES (145, "Nameless.", "Note Nul");
-- INSERT INTO reservations VALUES (13, 109, 12, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (24, 109, 34, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (37, 145, 84, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (49, 145, 45, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (51, 145, 41, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (68, 123, 3, "Mc Rayleigh Theater");
-- INSERT INTO reservations VALUES (83, 142, 46, "Mc Rayleigh Theater");
-------------------------------
SELECT p.id, p.title, SUM(r.number_of_tickets) AS reserved_tickets
FROM reservations r JOIN plays p
ON r.play_id = p.id
GROUP BY p.id ORDER BY reserved_tickets DESC, p.id ASC