Skip to content

Instantly share code, notes, and snippets.

View latompa's full-sized avatar

Thomas Olausson latompa

View GitHub Profile
@latompa
latompa / bayesian rating
Created January 8, 2009 01:02
bayesian rating
-- building on data from my scenario http://gist.github.com/44489
-- and bayesian rating http://www.thebroth.com/blog/118/bayesian-rating
assume we have a products table and we want to sort products based on their rating.
With bayesian rating, you get better weighting, so that a single 5 star vote won't show up as "top product"
select * from products;
mysql> select * from products;
+------+--------+---------------+--------------+---------+
| id | name | ratings_count | total_rating | weight |
@latompa
latompa / gist:44489
Created January 7, 2009 22:51
update with correlated query
-- I had an existing products table, and needed to denormalize two fields for faster sorting.
-- The number of rates and total rating is currently in a ratings table, and needs to be copied to products
create table products (
id integer,
name varchar(16),
ratings_count integer,
total_rating integer
);