Query to plot a histogram of song ratings
It would be better to use GROUP by in your SQL. By this way you will get rid of long SQL query.

SELECT Rating, COUNT(id) FROM list WHERE songID=:songID GROUP BY Rating;