You will need to do a
SUM()
in your selection, utilizing a
GROUP BY
to identify the breakup of the sums, a
CASE
statement to retrieve values, then use
ORDER BY
to sort them:
SELECT
Column1,
Column2,
SUM(
CASE
WHEN column3 IN ('S', 'M')
THEN 1
ELSE CAST(column3 AS int)
END
) AS SumOfColumn3
FROM
sourceTable
GROUP BY
Column1,
Column2
ORDER BY
Column1,
Column2