Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Forked from samccone/top_25.sql
Created October 21, 2024 00:17
Show Gist options
  • Save billywhizz/a2d90aa601f72a502f3167b78f0efa8b to your computer and use it in GitHub Desktop.
Save billywhizz/a2d90aa601f72a502f3167b78f0efa8b to your computer and use it in GitHub Desktop.
WITH RECURSIVE transitive_dependencies AS (
SELECT package_id AS dependency_id, package_id AS root_id
FROM dependencies
WHERE kind = 'runtime'
UNION ALL
SELECT d.package_id, td.root_id
FROM dependencies d
JOIN transitive_dependencies td ON td.dependency_id = d.package_id AND td.dependency_id <> td.root_id -- Avoid self-joins
WHERE d.kind = 'runtime'
),
dependency_counts AS (
SELECT root_id, COUNT(*) AS dependency_count
FROM transitive_dependencies
GROUP BY root_id
)
SELECT p.name, dc.dependency_count
FROM dependency_counts dc
JOIN packages p ON p.id = dc.root_id
ORDER BY dc.dependency_count DESC
LIMIT 25;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment