Please refer the db table image.

I want to count type with value ‘Q’ for each user id. I am confused either whatever I have written is correct or not.
"SELECT COUNT(type),userid FROM '$db_prefix'posts WHERE type=Q GROUP BY userid";
So where it will display total number of Q for x user id like below :
userid 1 has 25 Q
userid 2 has 11 Q
....
Same way for A and C but I think if I will get for Q than it will work in the same way for A and C.
You can actually get it for each type with a single query. Like this:
This query groups those rows that have the same value of BOTH type and userid.
Echo statement:
echo $q['userid'] .' has '. $q['n'] $q['type'] .' question';