Each product a product_date_added , which is a Date field, contains the date it was added. They also have product_views , which is an int field in which the number of times a product has been viewed.
To display products by popularity, I need an algorithm to calculate the number of hits per day of a product.
SELECT AVG(product_views / DATEDIFF(NOW(), product_date_added)) as avg_hits , product_table.* FROM product_table WHERE product_available = "yes" GROUP BY product_id ORDER BY avg_hits DESC
It works, but the boss notices how many old products appear first. Therefore, he basically wants newer looks to have more weight than old ones.
His suggestion was that any views older than a year were not taken into account. I think that I will need to adhere to the date of each look in order to do this, which, I think, will slow down the work.
What is the best way to create a popularity algorithm, like what my boss is asking for?
Ideally, I would like to be able to come up with something that does not change the structure of the table. If this is not possible, I would like at least to come up with a solution that can use existing data, so we do not start with 0. If this is not possible, or anything that will work.
source share