-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show package ranking #18
Comments
WITH results AS ( SELECT sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalDay(1) AND date <= {max_date:String}::Date32) AS last_day,
sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalWeek(1) AND date <= {max_date:String}::Date32) AS last_week,
sumIf(count, date > {min_date:String}::Date32 AND date > {max_date:String}::Date32 - toIntervalMonth(1) AND date <= {max_date:String}::Date32) AS last_month,
sumIf(count, date > {min_date:String}::Date32 AND date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32) AS total
FROM pypi.pypi_downloads_per_day WHERE (project = {package_name:String}) AND 1=1 AND 1=1
AND 1=1 ),
(
SELECT uniq(project) FROM (
SELECT project FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 GROUP BY project HAVING sum(count) > (SELECT total FROM results)
)
) as rank
SELECT rank, * FROM results solves but alittle slow |
better WITH
( SELECT
sum(count) AS total
FROM pypi.pypi_downloads_per_day WHERE project = {package_name:String} AND 1=1 AND 1=1 AND date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 AND 1=1
) AS downloads,
(SELECT count() FROM ( SELECT project FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 GROUP BY project HAVING sum(count) > downloads )) as rank,
(SELECT uniqExact(project) FROM pypi.pypi_downloads_per_day WHERE date > {min_date:String}::Date32 AND date <= {max_date:String}::Date32 ) as total_packages
SELECT rank, total_packages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
e.g. top 1% of packages downloaded.
Simple query. Add to downloads bar.
The text was updated successfully, but these errors were encountered: