How to get the count of each values

Hi Everyone,

I need to get the count based on column values.

Table Structure:

Company_ID Customer_ID Status
1 3453453 Sent
1 3488453 Error
1 3453453 Sending
2 4453453 Sent
3 3489453 Sent
2 1345453 Error
3 3487453 Sent
3 3453453 Sent
3 3454553 Sent

I need output like this,
Company_ID Sending Sent Error
1 1 1 1
2 0 1 1
3 0 4 0

Please tell the solution, I put many ways but not getting the exact output

DECLARE @t TABLE (Company_ID int , Customer_ID INT, Status VARCHAR(10))
INSERT INTO @t (Company_ID, Customer_ID, Status) VALUES
(1,	3453453,	'Sent'),
(1,	3488453,	'Error'),
(1,	3453453,	'Sending'),
(2,	4453453,	'Sent'),
(3,	3489453,	'Sent'),
(2,	1345453,	'Error'),
(3,	3487453,	'Sent'),
(3,	3453453,	'Sent'),
(3,	3454553,	'Sent')

SELECT Company_ID,
    COUNT(IIF(status = 'Sent', 1, NULL)) AS Sent,
    COUNT(IIF(status = 'Error', 1, NULL)) AS Error,
    COUNT(IIF(status = 'Sending', 1, NULL)) AS Sending
FROM @t
GROUP BY Company_ID
1 Like

Awesome, Thank you very much, it's coming perfectly