One method is to unpivot the data and then re-pivot. The following uses apply and conditional aggregation:
select v.stars,
sum(case when v.q = 'q1' then 1 else 0 end) as q1,
sum(case when v.q = 'q2' then 1 else 0 end) as q2,
sum(case when v.q = 'q3' then 1 else 0 end) as q3,
sum(case when v.q = 'q4' then 1 else 0 end) as q4,
. . .
from t cross apply
(values ('q1', q1), ('q2', q2), . . .
) v(q, stars)
group by v.stars
order by v.stars;
The need to unpivot the data suggests that you have a poor data model. You should really have a table with a separate row per q.
EDIT:
Here is an alternative method if you want to start with all the ratings:
select v.stars,
sum(case when t.q1 = v.stars then 1 else 0 end) as q1,
sum(case when t.q2 = v.stars then 1 else 0 end) as q2,
sum(case when t.q3 = v.stars then 1 else 0 end) as q3,
. . .
from (values (1), (2), (3), (4), (5)) v(stars) cross join
t
group by v.stars
order by v.stars;
COUNT()andUNION?