lundi 25 janvier 2016

computing an average- logic in sql vs php

I get back search results and each result has some numeric values of ratings associated with it in a mysql database. I need to get back the average rating of each result.

I think my options are to retrieve all the ratings with a query and then in my controller, using php, go over each result and compute its average rating. Or I can do something like

select avg(case when result_id = value1 then rating), avg(case when result_id = value2 ...
from my_table

Can someone offer some advice on which option is preferable? Also I am using Laravel, so perhaps that might help with some of the query options available.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/23nfiQ9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire