PIVOT
: hp+vertica+pivot.таблица с полями: id, month_id, kpi1, kpi2
чтобы стало: id, kpi1-2020-01-01, kpi1-2020-02-01, kpi2-2020-01-01, kpi2-2020-02-01.
PIVOT
SELECT ID, SUM(M1K1), SUM(M2K1), SUM(M1K2), SUM(M2K2) FROM
(SELECT ID, kpi1 AS M1K1, 0 AS M2K1, kpi2 AS M1K2, 0 AS M2K2 FROM Table_K WHERE month_id = 1
UNION
SELECT ID, 0, kpi1, 0, kpi2 FROM Table_K WHERE month_id = 2) AS DailyData
GROUP BY ID