A pivot ON clause selects the expression whose distinct values become columns. Other columns form grouping keys when an aggregate computes the cells. section 4.7
Pivot power by year
PIVOT (FROM v_power_per_day) ON year(day) USING sum(kWh); This produces one row per system and columns for 2019 and 2020, containing summed power values. section 4.7
The ON expression also controls the shape and meaning of the result:
- Use ON day to create a column for each distinct date; without USING, cells are filled with indicators for matching values. section 4.7
