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?.
create table it0422 (
xyear int not null
, q1 int not null
, q2 int not null
, q3 int not null
, q4 int not null
);
insert into it0422 values
(2017,200,250,235,266),
(2018,195,220,215,240);
select *
from it0422;
2 rows affected
xyear | q1 | q2 | q3 | q4 |
---|---|---|---|---|
2017 | 200 | 250 | 235 | 266 |
2018 | 195 | 220 | 215 | 240 |
select xyear as "年度"
, unnest(array['q1', 'q2', 'q3', 'q4']) as "各季"
, unnest(array[q1, q2, q3, q4]) as "購買金額"
from it0422
order by 1,2;
年度 | 各季 | 購買金額 |
---|---|---|
2017 | q1 | 200 |
2017 | q2 | 250 |
2017 | q3 | 235 |
2017 | q4 | 266 |
2018 | q1 | 195 |
2018 | q2 | 220 |
2018 | q3 | 215 |
2018 | q4 | 240 |