I have table.
Country Status
USA A
USA A
USA B
USA C
UK A
UK D
UK D
China A
China A
China C
China C
I want to write a query and display the result in table like below.
Country A B C D Total
USA 2 1 1 0 4
UK 1 0 0 2 3
China 2 0 2 0 4
Total 5 1 3 2 11
$q="SELECT Country,Status,Count(Status) as Stat Group BY Country,Status";
$r=mysql_query($q);
while($o=mysql_fetch_object($r)){
$t .="<tr>
<td>$o->Country</td>
<td>$o->Status</td>
<td>$o->Stas</td>
</tr>";
}
It outputs. Which I want like above. It groups the country and status but i don't want to display country multiple times. and i want to display the row output of Status as column and display it counts.
USA A 2
USA B 1
USA C 1
UK A 1
UK D 2
China A 2
China C 2