Created
May 26, 2015 04:58
-
-
Save doryokujin/2f75d16adad338c3f0f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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