SELECT * FROM pivot (
ON pivot_input
PARTITION BY sn, city, week
ORDER BY week
PartitionColumns ('sn', 'city', 'week')
NumberOfRows (3)
TargetColumns ('value')
) ORDER BY 1,2,3;
The ORDER BY clause is optional. If omitted, the order of values can vary. The function always adds any NULL values at the end.