我想使用以下来自how to not sort by average rating的Wilson分数置信度查询,根据用户搜索时间过去24小时内的投票计算相关内容。我将unix时间戳存储在字段中但不是datetime
类型。
现在查询是:
SELECT p.id, p.post, p.upvotes, p.downvotes, ((upvotes + 1.9208) / (upvotes + downvotes) -
1.96 * SQRT((upvotes * downvotes) / (upvotes + downvotes) + 0.9604) /
(upvotes + downvotes)) / (1 + 3.8416 / (upvotes + downvotes))
AS ci_lower_bound FROM posts p WHERE upvotes + downvotes > 0
ORDER BY ci_lower_bound DESC;
我需要获取过去24小时内发布的热门内容。我知道我需要使用WHERE
添加BETWEEN
条件,但不确定如何?
请帮忙。
更新根据以下答案和一些调整我做了类似的事情:
SELECT p.id, p.post, p.upvotes, p.downvotes, ((upvotes + 1.9208) / (upvotes + downvotes) - 1.96 * SQRT((upvotes * downvotes)
/ (upvotes + downvotes) + 0.9604) / (upvotes + downvotes))
/ (1 + 3.8416 / (upvotes + downvotes)) AS ci_lower_bound
FROM posts p WHERE upvotes + downvotes > 0
AND p.unix_timestamp BETWEEN 1363023402 AND 1363109802 ORDER BY ci_lower_bound DESC
通过从当前时间戳减去86400秒(即24小时)并得到结果来计算的第一个值。如果你认为它仍然可以改进,请建议我。
答案 0 :(得分:1)
SELECT *, complex_formula
FROM posts
WHERE upvotes + downvotes > 0
AND ts BETWEEN UNIX_TIMESTAMP($user_time - INTERVAL 1 DAY) AND UNIX_TIMESTAMP($user_time)