Skip to content

Instantly share code, notes, and snippets.

@abnersajr
Created October 7, 2022 04:03
Show Gist options
  • Save abnersajr/0b2544219d199ce136b72c9c9e4cf61b to your computer and use it in GitHub Desktop.
Save abnersajr/0b2544219d199ce136b72c9c9e4cf61b to your computer and use it in GitHub Desktop.
WITH ranks AS (
SELECT
menu_category,
menu_items,
energy_kcal,
row_number() OVER (
PARTITION BY menu_category
ORDER BY
energy_kcal DESC
) as energy_kcal_rank
FROM
menu
)
SELECT
*
FROM
ranks
WHERE
energy_kcal_rank <= 3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment