т.е. Вы можете агрегировать результаты вашего поворота. Я не уверен, каковы ваши требования в отношении, например, hora
.
WITH Pivoted
AS
(
SELECT
*
FROM
(
SELECT [usuario],
[codtrab],
[tna],
[hora],
[tipo],
[fecha]
FROM prueba
group by [usuario],
) AS SourceTable PIVOT(AVG([tna]) FOR [tipo] IN([entrada], [salida])) AS PivotTable
)
SELECT
[usuario],
[codtrab],
min([hora]) as [hora],
[fecha],
max(entrada) as entrada,
max(salida) as salida
FROM Pivoted
GROUP BY [usuario], [codtrab], [fecha] ;