dimanche 28 décembre 2014

SUM(Value) Group By After PIVOT

Hi everybody (happy merry christmas)


I have the following query for Pivot, that works nice.



WITH PivotData AS
(
SELECT fechaHora, idWatimetro, semana, hora, minuto,dia,mes ,ano,valor
FROM E_Registros_Watimetros
)
SELECT *
FROM PivotData
PIVOT(SUM(valor) FOR idWatimetro IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10]) ) AS P order by fechaHora, semana,dia,mes;


enter image description here


But now, I must be able to get Sum(valor) for every month or days or weeks or Year, but I´m trying without success, any help will be nice


Thank you for your time.


Aucun commentaire:

Enregistrer un commentaire