Skip to content

Instantly share code, notes, and snippets.

@javrasya
Created December 27, 2019 14:16
Show Gist options
  • Save javrasya/63b15a5548c160c0c1dd741f3cb824ed to your computer and use it in GitHub Desktop.
Save javrasya/63b15a5548c160c0c1dd741f3cb824ed to your computer and use it in GitHub Desktop.
SELECT
p.category,
p.product_name,
p.product_description
FROM (
SELECT
p.category,
p.product_name,
p.product_description,
(percent_rank() OVER w1) * 100 AS percent_rnk
FROM products p
window w1 AS ( PARTITION BY p.category ORDER BY p.product_id)
)t1
WHERE t1.percent_rnk<50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment