Then maybe this:select coalesce(d.[Vendor Name], 'Other') as [Vendor Name] ,sum(t.Quantity) as TotalQuantityfrom [yourTable] tleft outer join ( select top 5 [Vendor Name] from [yourTable] group by [Vendor Name] order by sum(Quantity) desc ) d on d.[Vendor Name] = t.[vendor name]group by case when d.[vendor name] is null then 1 else 0 end ,coalesce(d.[Vendor Name], 'Other') order by case when d.[vendor name] is null then 1 else 0 end ,sum(t.Quantity) desc
EDIT:added the sort to match your exampleBe One with the OptimizerTG