Je préfère utiliser la solution GROUP BY avec l'expression CASE.
SELECT
id,
MAX(CASE WHEN emailRank = 1 THEN email END) AS [1],
MAX(CASE WHEN emailRank = 2 THEN email END) AS [2],
MAX(CASE WHEN emailRank = 3 THEN email END) AS [3],
MAX(CASE WHEN emailRank = 4 THEN email END) AS [4]
FROM (
SELECT
id,
email,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY email) AS emailRank
FROM TABLE
)
GROUP BY id;
L'exemple original de Pivot avait un type et il manquait ")". Essayez ce qui suit pour que le pivot fonctionne :
pivot( max(email) FOR emailRank IN (1,2,3));