Skip to content

Instantly share code, notes, and snippets.

@wenqiglantz
Created July 29, 2023 17:05
Show Gist options
  • Save wenqiglantz/ab2a7427bd55319eee837bc0ddfde065 to your computer and use it in GitHub Desktop.
Save wenqiglantz/ab2a7427bd55319eee837bc0ddfde065 to your computer and use it in GitHub Desktop.
/*
Pull the repos with the most stars in the past year
*/
WITH latest_repo_name AS (
SELECT repo_name,
repo_id
FROM cybersyn.github_repos
QUALIFY ROW_NUMBER() OVER (PARTITION BY repo_id ORDER BY first_seen DESC) = 1
)
SELECT repo.repo_name,
repo.repo_id,
SUM(stars.count) AS sum_stars
FROM cybersyn.github_stars AS stars
JOIN latest_repo_name AS repo
ON (repo.repo_id = stars.repo_id)
WHERE stars.date >= DATEADD('day', -365, CURRENT_DATE)
GROUP BY repo.repo_name, repo.repo_id
ORDER BY sum_stars DESC NULLS LAST
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment