<分区>
我正在尝试制作一个与 Hacker News 类似的网站我发现这个算法需要帮助我对我网站上的链接进行排序,这里是:
Score = (P-1) / (T+2)^G
where,
P = points of an item (and -1 is to negate submitters vote)
T = time since submission (in hours)
G = Gravity, defaults to 1.8 in news.arc
所以我需要创建一个 SQL 查询,该查询将使用上述等式对数据进行排序,但我不知道该怎么做。这是我的表结构:
Table 1 name: links
Table 1 fields: id, title, url, user_id, created_at
Table 2 name: votes
Table 2 fields: id, user_id, link_id, vote, created_at
在表 2 中,投票可以是三个值之一:1、0、-1
那么这甚至可以用 SQL 来做,还是我必须以其他方式来做?