Someone can easily explain me an example with PIVOT to transpose columns by rows in sql.
I have several data represented as follows:
FECHA ERROR1 ERROR2
2017-01-01 12 23
And I would like to transpose them like this:
FECHA TIPO DE ERROR TOTAL
2017-01-01 ERROR1 12
2017-01-01 ERROR2 23
The code I have:
SELECT [1] as Fecha, [2] as TìpoError, [3] as Total
FROM
(SELECT ERROR1,ERROR2
FROM Errores) AS SourceTable
PIVOT
(
AVG(ERROR1)
FOR ERROR1, ERROR2 IN ([1], [2], [3])
) AS TablaEjemplo;
I can not find an example that is simple to move forward with this query.