-
-
Save finbarr/e556ccf7a2b6fc496861697d8e2708ee to your computer and use it in GitHub Desktop.
Query to find Shopify apps that reached 1000 reviews with no score less than 3 stars.
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
WITH ranked_reviews AS ( | |
SELECT | |
a.name AS app_name, | |
a.id AS app_id, | |
RANK() OVER ( | |
PARTITION BY r.app_id | |
ORDER BY | |
r.posted_at ASC | |
) AS rank, | |
r.score, | |
r.posted_at | |
FROM | |
apps a | |
INNER JOIN reviews r ON r.app_id = a.id | |
) | |
SELECT | |
name | |
FROM | |
apps | |
WHERE | |
EXISTS( | |
SELECT | |
1 | |
FROM | |
ranked_reviews | |
WHERE | |
app_id = apps.id | |
AND rank >= 1000 | |
) | |
AND NOT EXISTS( | |
SELECT | |
1 | |
FROM | |
ranked_reviews | |
WHERE | |
app_id = apps.id | |
AND rank <= 1000 | |
AND score < 3 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment