참고

Pivoting

CROSSTAB

모듈 설치

CREATE EXTENSION IF NOT EXISTS tablefunc;

예제 테이블

CREATE TABLE tbl (
   SECTION   TEXT
 , STATUS    TEXT
 , CNT       INTEGER
);

INSERT INTO tbl VALUES
  ('A', 'Active', 1), ('A', 'Inactive', 2)
, ('B', 'Active', 4), ('B', 'Inactive', 5)
                    , ('C', 'Inactive', 7);  -- ('C', 'Active')가 없음

CROSSTAB(TEXT)

SELECT *
  FROM CROSSTAB(

      'SELECT SECTION, STATUS, CNT
       FROM   tbl
       ORDER  BY 1, 2'

) AS T ("Section" TEXT, "Active" INT, "Inactive" INT);