Ever received data where the months were column headers, like below?
Ever felt the need to do something unspeakable to your keyboard, right after?
You are not alone.
However! Fear not, because there is salvation. Thou needst only use the UNPIVOT function in Snowflake, and rest, peace and Eden will return to your data landscape.
Behold, the cure:
SQL
WITH MONTHLY_SALES AS (
SELECT
*
FROM (VALUES
(1, 'electronics', 100, 200, 300, 100),
(2, 'clothes', 100, 300, 150, 200),
(3, 'cars', 200, 400, 100, 50)
) as t(EMPID, DEPARTMENT, JAN, FEB, MAR, APR)
)
SELECT
*
FROM MONTHLY_SALES
UNPIVOT(SALES FOR MONTH IN (JAN, FEB, MAR, APR))
;SQL