select org.ShortName Организация,O.ObjectGarNum Гаражный_N,d.code АТ, Count_all.c as Всего_коорд,Count_ign.c as ЧЯ_коорд, cast(round(((0.0000+Count_ign.c)/Count_all.c*100),2) as float) as Процент from bn.[dbo].[FLEET_Object] as O
inner join bn.dbo.SYS_DEV_Device as D on d.id=O.Device_ID
left join bn.dbo.SYS_OrgRequisite as Org on Org.id=O.OrganizationId
inner hash join (select ObjectID, Count(*) c from bn.dbo.SYS_DEV_ArchiveData
where tele_time >=dateadd (dd,-30,getdate())
group by ObjectID) as Count_all on Count_all.ObjectID=O.ObjectID
inner hash join (select AD.ObjectID, Count(ad.id) c from bn.dbo.SYS_DEV_ArchiveData as AD
where ad.tele_time >=dateadd (dd,-30,getdate()) and ad.flags&4=0
group by ObjectID) as Count_ign on Count_ign.ObjectID=O.ObjectID where o.ObjectActive=1 order by cast(round(((0.0000+Count_ign.c)/Count_all.c*100),2) as float) desc