Created
April 2, 2013 08:29
-
-
Save mraaroncruz/5290766 to your computer and use it in GitHub Desktop.
Hacker News algorithm in SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT x.* | |
FROM POSTS x | |
JOIN (SELECT p.postid, | |
SUM(v.vote) AS points | |
FROM POSTS p | |
JOIN VOTES v ON v.postid = p.postid | |
GROUP BY p.postid) y ON y.postid = x.postid | |
ORDER BY (y.points - 1)/POW((((UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(x.timestamp))/3600)+2, 1.5) DESC | |
LIMIT n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment