Code
use [BNComplex1]
/****** Сценарий для команды SelectTopNRows среды SSMS ******/
declare @t table (Describtion nvarchar(64),devnum varchar(15),BillingDayDate datetime,msgwithGPS int,MsgWithoutGPS int )
insert into @t
SELECT ad.Describtion
,d.DevNum
,bd.BillingDayDate
,msgwithGPS
,MsgWithoutGPS
FROM [dbo].[BillingData] as BD
inner join dbo.Devices as D on d.DeviceID=bd.[DeviceID]
inner join dbo.AreaDescr as AD on AD.AreaID=bd.AreaID
--group by ad.Describtion,d.DevNum,CONVERT (datetime,[bd.BillingDayDate],102)
select * from @t
select Describtion,devnum, CONVERT(varchar(7),BillingDayDate,102) as mes,SUM(msgwithGPS) msgwithGPS
,SUM(MsgWithoutGPS) MsgWithoutGPS
from @t
group by Describtion,devnum,CONVERT(varchar(7),BillingDayDate,102)
order by Describtion,devnum,CONVERT(varchar(7),BillingDayDate,102)
на выходе две таблицы:
в разрезе дней для каждого прибора
и в разрезе месяцев для каждого прибора
для прибора указан его номер, и область