Skip to content

Instantly share code, notes, and snippets.

@maratuska
Last active February 21, 2023 09:44
Show Gist options
  • Save maratuska/008964a39225a06653dad6ca952a3c46 to your computer and use it in GitHub Desktop.
Save maratuska/008964a39225a06653dad6ca952a3c46 to your computer and use it in GitHub Desktop.
WITH charge_by_categories AS (
SELECT
ca.category_no,
ca.category_desc,
ch.charge_amt
FROM charge ch
JOIN category ca
ON ch.category_no = ca.category_no
)
SELECT
cbc.category_desc,
SUM(cbc.charge_amt) summary_charge
FROM charge_by_categories cbc
GROUP BY cbc.category_no
ORDER BY summary_charge DESC
LIMIT 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment