Skip to content

Instantly share code, notes, and snippets.

@doryokujin
Created May 26, 2015 04:58
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/2f75d16adad338c3f0f9 to your computer and use it in GitHub Desktop.
Save doryokujin/2f75d16adad338c3f0f9 to your computer and use it in GitHub Desktop.
SELECT
goods_id, sub_category, category,
COUNT(1) OVER (PARTITION BY sub_category) AS record_number_subcat,
COUNT(1) OVER (PARTITION BY category) AS record_number_cat,
--1.0*record_number_subcat/record_number_cat AS percent_of_record_number--
SUM(amount) OVER (PARTITION BY sub_category) AS total_amount_subcat,
SUM(amount) OVER (PARTITION BY category) AS total_amount_cat,
--1.0*total_amount_subcat/total_amount_cat AS percent_of_total_amount--
SUM(price*amount) OVER (PARTITION BY sub_category) AS total_sales_subcat,
SUM(price*amount) OVER (PARTITION BY category) AS total_sales_cat
--1.0*total_sales_subcat/total_sales_cat AS percent_of_total_sales--
FROM sales_slip_10k
ORDER BY sub_category, category
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment