CREATE table #yourtable ([Id] int, [Type] int) ; INSERT ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

CREATE table #yourtable
    ([Id] int, [Type] int)
;
    
INSERT INTO #yourtable
    ([Id], [Type])
VALUES
    (1, 1),
    (2, 2),
    (3, 1),
    (4, 2),
    (5, 3)
;


select SUM(CASE WHEN [Type] = 1 THEN 1 ELSE 0 END)
  , SUM(CASE WHEN [Type] = 2 THEN 1 ELSE 0 END)
  , SUM(CASE WHEN [Type] = 3 THEN 1 ELSE 0 END)
FROM #yourtable

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results