1

I have a table like

create temp table x (
    id integer,
    date date,
    month integer,
    cost integer);

insert into x values
    (1, '2022-09-01', 1, 5),
    (1, '2022-09-01', 2, 20),
    (1, '2022-09-01', 3, 33),
    (1, '2022-09-01', 4, 39),
    (1, '2022-09-01', 5, 44),
    (1, '2022-09-01', 6, 60),
    (1, '2022-09-01', 7, 72),
    (2, '2022-11-01', 1, 11),
    (2, '2022-11-01', 2, 14),
    (2, '2022-11-01', 3, 26),
    (2, '2022-11-01', 4, 55),
    (2, '2022-11-01', 5, 99),
    (3, '2023-01-01', 1, 1),
    (3, '2023-01-01', 2, 3),
    (3, '2023-01-01', 3, 4);

I'd like to pivot the cost and month columns so the table looks like this:

enter image description here

Raksha
  • 1,572
  • 2
  • 28
  • 53

0 Answers0