Skip to content

Instantly share code, notes, and snippets.

@mfridman
Created November 8, 2019 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfridman/7e6e0febdbdacbb236fe5ff44bc87156 to your computer and use it in GitHub Desktop.
Save mfridman/7e6e0febdbdacbb236fe5ff44bc87156 to your computer and use it in GitHub Desktop.
finding top comments
WITH votes AS (
SELECT
number_id,
id,
SUM(CAST(plus_one + 1 AS FLOAT)) AS U,
SUM(CAST(minus_one + 1 AS FLOAT)) AS D
FROM
comments
GROUP BY
id,
number_id
)
SELECT
FORMAT('[%s](https://github.com/golang/go/issues/%s)', number_id, number_id),
FORMAT('[%s](https://github.com/golang/go/issues/%s#issuecomment-%s)', id, number_id, id),
U - 1 AS 👍,
D - 1 AS 👎,
ABS(0.5 - U / (U + D) - 3.5 * SQRT(U * D / ((U + D) * (U + D) * (U + D + 1)))) +
ABS(0.5 - U / (U + D) + 3.5 * SQRT(U * D / ((U + D) * (U + D) * (U + D + 1)))) AS Score
FROM
votes
ORDER BY
Score
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment