might be this will be handy and more readable
with cte as (
SELECT DISTINCT t1.DealerID, t2.tire,
TotalRepairs = SUM(1) OVER (PARTITION BY t1.DealerID),
RepairsOfThisTire = SUM(1) OVER(PARTITION BY t1.DealerID, t2.tire),
PercentOfTotalRepairOrders = ROUND((SUM(1.0) OVER(PARTITION BY t1.DealerID, t2.tire)/SUM(1.0) OVER (PARTITION BY t1.DealerID)) *100,0)
FROM dbo.Table1 t1
LEFT JOIN dbo.Table2 t2
ON t2.RepairId = t1.RepairId
)
SELECT * FROM cte
WHERE tire IS NOT NULL
ORDER BY PercentOfTotalRepairOrders DESC
since you are using Sql 2012 you can use Lead or Lag function to calculate Total percent by Dealer Group and you can get the desire result
Every rule in a world of bits and bytes, can be bend or eventually be broken
MyBlog About Common dialog control
A Visualizer for viewing SqlCommand object script [/url]