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?.
DROP TABLE
CREATE TABLE
INSERT 0 49
dte
2022-01-01
2022-02-01
2022-03-01
2022-04-01
2022-05-01
2022-06-01
2022-07-01
2022-08-01
2022-09-01
2022-10-01
2022-11-01
2022-12-01
SELECT 12
dte total
2022-01-01 22030
2022-02-01 22753
2022-03-01 0
2022-04-01 9456
2022-05-01 7798
2022-06-01 38278
2022-07-01 18736
2022-08-01 6794
2022-09-01 21033
2022-10-01 28576
2022-11-01 10172
2022-12-01 41901
SELECT 12
pivotdata
{"2022-01": 22030, "2022-02": 22753, "2022-03": 0, "2022-04": 9456, "2022-05": 7798, "2022-06": 38278, "2022-07": 18736, "2022-08": 6794, "2022-09": 21033, "2022-10": 28576, "2022-11": 10172, "2022-12": 41901}
SELECT 1
jan feb mar apr may jun jul aug sep oct nov dec
22030 22753 0 9456 7798 38278 18736 6794 21033 28576 10172 41901
SELECT 1
dte customer_id
2022-01-01 00:00:00+00 2
2022-01-01 00:00:00+00 1
2022-02-01 00:00:00+00 2
2022-02-01 00:00:00+00 1
2022-03-01 00:00:00+00 2
2022-03-01 00:00:00+00 1
2022-04-01 00:00:00+01 2
2022-04-01 00:00:00+01 1
2022-05-01 00:00:00+01 2
2022-05-01 00:00:00+01 1
2022-06-01 00:00:00+01 2
2022-06-01 00:00:00+01 1
2022-07-01 00:00:00+01 2
2022-07-01 00:00:00+01 1
2022-08-01 00:00:00+01 2
2022-08-01 00:00:00+01 1
2022-09-01 00:00:00+01 2
2022-09-01 00:00:00+01 1
2022-10-01 00:00:00+01 2
2022-10-01 00:00:00+01 1
2022-11-01 00:00:00+00 2
2022-11-01 00:00:00+00 1
2022-12-01 00:00:00+00 2
2022-12-01 00:00:00+00 1
SELECT 24
dte customer_id total
2022-12-01 00:00:00+00 1 14447
2022-04-01 00:00:00+01 2 4057
2022-09-01 00:00:00+01 1 14
2022-03-01 00:00:00+00 1 0
2022-03-01 00:00:00+00 2 0
2022-05-01 00:00:00+01 1 0
2022-06-01 00:00:00+01 2 23457
2022-01-01 00:00:00+00 2 22030
2022-12-01 00:00:00+00 2 27454
2022-10-01 00:00:00+01 2 13110
2022-08-01 00:00:00+01 2 6794
2022-08-01 00:00:00+01 1 0
2022-02-01 00:00:00+00 1 10170
2022-02-01 00:00:00+00 2 12583
2022-10-01 00:00:00+01 1 15466
2022-11-01 00:00:00+00 1 3675
2022-05-01 00:00:00+01 2 7798
2022-01-01 00:00:00+00 1 0
2022-06-01 00:00:00+01 1 14821
2022-04-01 00:00:00+01 1 5399
2022-07-01 00:00:00+01 2 10809
2022-09-01 00:00:00+01 2 21019
2022-07-01 00:00:00+01 1 7927
2022-11-01 00:00:00+00 2 6497
SELECT 24
customer_id pivotdata
2 {"2022-01": 22030, "2022-02": 12583, "2022-03": 0, "2022-04": 4057, "2022-05": 7798, "2022-06": 23457, "2022-07": 10809, "2022-08": 6794, "2022-09": 21019, "2022-10": 13110, "2022-11": 6497, "2022-12": 27454}
1 {"2022-01": 0, "2022-02": 10170, "2022-03": 0, "2022-04": 5399, "2022-05": 0, "2022-06": 14821, "2022-07": 7927, "2022-08": 0, "2022-09": 14, "2022-10": 15466, "2022-11": 3675, "2022-12": 14447}
SELECT 2
customer_id jan feb mar apr may jun jul aug sep oct nov dec
1 0 10170 0 5399 0 14821 7927 0 14 15466 3675 14447
2 22030 12583 0 4057 7798 23457 10809 6794 21019 13110 6497 27454
SELECT 2