Add to SQL or PHP for better performance and less weight on the server?

0

I am working on a voting system (5 star ratings), and I want to get the total vote amounts divided by 5 and 1 to show the percentage of each note. However I could do a select already with the sum of everything as ex:

SELECT SUM(rating = '5') as v5, 
SUM(rating = '4') as v4,
SUM(rating = '3') as v3,
SUM(rating = '2') as v2,
SUM(rating = '1') as v1

FROM 'table_ratings' WHERE post_id = '27';

What gives me the number of votes for each note, and then I multiply with php to get what I want.

Or should I just get all the votes that can give a lot of data and work in php?

SELECT rating from 'table_ratings' WHERE post_id = '27';

Which will perform better and weigh less the server and the database?

    
asked by anonymous 09.11.2018 / 00:21

0 answers