SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE VIEW [dbo].[v_StatsCall]
AS

WITH cteDati AS
(
	SELECT YEAR(DataRif) AS YearRef, CodInst, CodApp, SUM(NumCall) AS TotCall
	FROM LogCall
	GROUP BY YEAR(DataRif), CodInst, CodApp
)

SELECT	*
FROM	cteDati
ORDER BY YearRef DESC, TotCall DESC

GO