Skip to content

Instantly share code, notes, and snippets.

@finbarr
Created August 14, 2018 00:52
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 finbarr/2683f1dfcea7174555ddf4ef10ecc375 to your computer and use it in GitHub Desktop.
Save finbarr/2683f1dfcea7174555ddf4ef10ecc375 to your computer and use it in GitHub Desktop.
Query to find Shopify apps with that reached 500 reviews without any review below 3 stars.
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 >= 500
)
AND NOT EXISTS(
SELECT
1
FROM
ranked_reviews
WHERE
app_id = apps.id
AND rank <= 500
AND score < 3
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment