Skip to content

Instantly share code, notes, and snippets.

@doryokujin
Last active August 29, 2015 14:21
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 doryokujin/f9b71bff6d32271ca132 to your computer and use it in GitHub Desktop.
Save doryokujin/f9b71bff6d32271ca132 to your computer and use it in GitHub Desktop.
SELECT
goods_id, sub_category, category,
COUNT(1) OVER (PARTITION BY category) AS record_number,
SUM(amount) OVER (PARTITION BY category) AS total_amount,
SUM(price*amount) OVER (PARTITION BY category) AS total_sales
FROM sales_slip_10k
ORDER BY goods_id, sub_category, category
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment