A PIVOT USING clause supplies the aggregate expressions that calculate each pivoted cell. For example, USING sum(kWh) turns daily power records into yearly totals for each system, while non-pivot columns such as system_id remain grouping keys. section 4.7
Yearly power totals
PIVOT (FROM v_power_per_day) ON year(day) USING sum(kWh); section 4.7
The clause can apply different aggregates at once. ROUND(SUM(kWh)) can produce a total, while MAX(kWh) identifies the best day; aliases become output-column suffixes such as 2019_total and 2019_best_day. section 4.7
Listing 4.26 Using DuckDB’s PIVOT statement
PIVOT (FROM v_power_per_day) #1 ON year(day) #2 USING sum(kWh); #3
Run the compact DuckDB PIVOT example and inspect how the USING aggregate creates one value per system-and-year cell. section 4.7
