How can I structure my ordering database by a time dependent function in MySQL?
I have a table with ID and KPI like this
+----+---------------------+------------+--------+
| id | created_at | page_views | shares |
+----+---------------------+------------+--------+
| 1 | 2015-02-25 07:24:50 | 10 | 3 |
| 2 | 2015-04-22 13:48:46 | 40 | 1 |
| 3 | 2014-09-17 15:26:51 | 28 | 5 |
| 4 | 2014-08-09 16:27:48 | 149 | 2 |
| 5 | 2015-01-21 15:56:30 | 3 | 1 |
+----+---------------------+------------+--------+
I want to create a row ranking algorithm
SELECT id FROM pages ORDER BY (pages.page_views + pages.shares * 40) / (NOW() - created_at);
But I feel it doesn't scale as the number of KPIs and inputs increases. Is there a way to structure my spreadsheet for ranking efficiently using KPIs with decreasing score over time?
+3
source to share