SELECT
category_id,
DATEPART(m, date_pub) AS 'month'
COUNT(category_id) AS cat_cnt,
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS status_1_cnt,
SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS status_2_cnt,
SUM(CASE WHEN status = 3 THEN 1 ELSE 0 END) AS status_3_cnt,
SUM(CASE WHEN status = 4 THEN 1 ELSE 0 END) AS status_4_cnt,
SUM(CASE WHEN status = 5 THEN 1 ELSE 0 END) AS status_5_cnt,
FROM
zakazy
GROUP BY
category_id,
DATEPART(m, date_pub)