Skip to content

[Style Guide] PIVOT #5

@jaypark72

Description

@jaypark72

PIVOT

Example 1. Simple Pivot
SELECT * FROM (
  SELECT ID, import, status FROM mytable
) PIVOT (SUM(import) FOR status in ('Authorized', 'Rejected'));
Example 2. Pivot w/ Multi-columns Aggregation
WITH initTable AS (
 -- put sample data here
),
pivotTable AS (
  SELECT * FROM initTable
   PIVOT (
     MAX(total) total, ANY_VALUE(name) name
     FOR fecData IN ('202301', '202302', '202303')
   )
)
SELECT * FROM pivotTable;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions