Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles
CREATE table #yourtable ([Id] int, [Type] int) ; INSERT INTO #yourtable ([Id], [Type]) VALUES (1, 1), (1, 2), (3, 1), (4, 2), (5, 3) ; select Id,SUM(CASE WHEN [Type] = 1 THEN 1 ELSE 0 END) as FP1 , SUM(CASE WHEN [Type] = 2 THEN 1 ELSE 0 END) as FP2 , SUM(CASE WHEN [Type] = 3 THEN 1 ELSE 0 END) as FP3 FROM #yourtable GROUP BY Id