Skip to content

Instantly share code, notes, and snippets.

@javrasya
Created December 27, 2019 14:12
Show Gist options
  • Save javrasya/95c57739caf107afb2ae09a9b4d048dc to your computer and use it in GitHub Desktop.
Save javrasya/95c57739caf107afb2ae09a9b4d048dc 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,
rank() over w1 rnk
FROM products p
window w1 AS ( PARTITION BY p.category ORDER BY p.product_id)
)t1
WHERE t1.rnk<2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment