Код
use bn
go
/****** Сценарий для команды SelectTopNRows среды SSMS ******/
SELECT O.ObjectGarNum ТС,sen.num ДУТ,sen.description, count(*) Точек, MAX(AnTar.MinValue_Tar) Объем
FROM [BN].[dbo].[FLEET_AnalogTarirovka] as AnTar
inner join dbo.SYS_DEV_Sensor as sen on Sen.id=AnTar.IDSensor
inner join dbo.SYS_DEV_Device as D on Sen.device_id=d.id
inner join dbo.FLEET_Object as O on O.Device_ID=d.id
inner join dbo.SYS_OrgRequisite as Org on O.OrganizationId=Org.id
where O.ObjectActive=1 and org.ShortName = 'БРУ' and sen.SensorActive=1
group by O.ObjectGarNum,sen.num,sen.description
order by O.ObjectGarNum,sen.num