add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
version
PostgreSQL 12.5 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.3.1 20191121 (Red Hat 8.3.1-5), 64-bit
2 rows affected
theatre_id theatre_name
1 Theatre_1
2 Theatre_2
4 rows affected
show_id show_theatre_id show_name
10 1 show_10
11 1 show_11
20 2 show_20
21 2 show_21
29 rows affected
ticket_id ticket_show_id price
1 10 10
2 10 10
3 10 10
4 10 10
5 10 10
29 10 500
26 10 500
27 10 500
28 10 500
10 11 11
11 11 11
12 11 11
6 11 11
7 11 11
8 11 11
9 11 11
17 20 20
18 20 20
19 20 20
20 20 20
21 20 20
22 20 20
14 20 20
15 20 20
16 20 20
13 20 20
23 21 21
24 21 21
25 21 21
theatre_id th_name s_id s_th s_name t_id t_show t_p
1 Theatre_1 10 1 show_10 1 10 10
1 Theatre_1 10 1 show_10 2 10 10
1 Theatre_1 10 1 show_10 3 10 10
1 Theatre_1 10 1 show_10 4 10 10
1 Theatre_1 10 1 show_10 5 10 10
1 Theatre_1 10 1 show_10 29 10 500
1 Theatre_1 10 1 show_10 26 10 500
1 Theatre_1 10 1 show_10 27 10 500
1 Theatre_1 10 1 show_10 28 10 500
1 Theatre_1 11 1 show_11 10 11 11
1 Theatre_1 11 1 show_11 11 11 11
1 Theatre_1 11 1 show_11 12 11 11
1 Theatre_1 11 1 show_11 6 11 11
1 Theatre_1 11 1 show_11 7 11 11
1 Theatre_1 11 1 show_11 8 11 11
1 Theatre_1 11 1 show_11 9 11 11
2 Theatre_2 20 2 show_20 17 20 20
2 Theatre_2 20 2 show_20 18 20 20
2 Theatre_2 20 2 show_20 19 20 20
2 Theatre_2 20 2 show_20 20 20 20
2 Theatre_2 20 2 show_20 21 20 20
2 Theatre_2 20 2 show_20 22 20 20
2 Theatre_2 20 2 show_20 14 20 20
2 Theatre_2 20 2 show_20 15 20 20
2 Theatre_2 20 2 show_20 16 20 20
2 Theatre_2 20 2 show_20 13 20 20
2 Theatre_2 21 2 show_21 23 21 21
2 Theatre_2 21 2 show_21 24 21 21
2 Theatre_2 21 2 show_21 25 21 21
Theatre name Show name Sales/show
Theatre_1 show_10 2050
Theatre_1 show_11 77
Theatre_2 show_20 200
Theatre_2 show_21 63
T. name Show name Tkt price Sales/T. Sales/show Tkts/show Sales/ticket
Theatre_1 10 500 521 510 2 2000
Theatre_1 10 10 521 510 2 50
Theatre_1 11 11 521 11 1 77
Theatre_2 20 20 41 20 1 200
Theatre_2 21 21 41 21 1 63
ERROR:  column "t.price" must appear in the GROUP BY clause or be used in an aggregate function
LINE 12:   SUM(t.price) OVER (PARTITION BY s.show_id ORDER BY th.thea...
               ^

count
9
7
3
10
ERROR:  more than one row returned by a subquery used as an expression