I want to regularly update the rows in a database but also want more popular rows (rows that are requested more) to be updated more often. I thought I could base this on two parameters: popularity and time since the last update.
id | title | popularity | last_updated
---+-------+------------+-------------
1 | A | 148 | 20190501
2 | B | 3874 | 20190201
3 | C | 29 | 20190104
4 | D | 242 | 20190314
5 | E | 398 | 20190325
6 | F | 3 | 20190128
The last_updated
column is formated as YYYYMMDD
.
I first thought I could simply use ORDER BY
:
SELECT * FROM results ORDER BY last_updated, popularity;
However, this query will only care about the last_updated
column if the value of two or more rows' popularity
is the same.
Would it be possible to e.g. turn popularity
and last_updated
into another value that can be used for this kind of sorting?