mysql count

Hi have a table as follows:

id    name       status
1      AA              1
2      AA             1
3      BB              1
4       AA             2
5       BB              2
6       BB              2


The output I am looking for is as follows, is this possible?

name    count_status 1        count_status 2
AA           2                                    1
BB           1                                     2

Thanks for the help.

A
aej1973Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Daniel WilsonConnect With a Mentor Commented:
That technique works reasonably well when there's a fixed (preferably small) number of statuses to be counted.
0
 
Daniel WilsonCommented:
select name,
sum(case when status = 1 then 1 else 0 end) as count_status1,
sum(case when status = 2 then 1 else 0 end) as count_status2
From MyTable group by name
0
 
aej1973Author Commented:
Thank you Daniel, this solution worked for me.

A
0
All Courses

From novice to tech pro — start learning today.