Created
May 26, 2015 04:12
-
-
Save doryokujin/0a4baa76742e439d3558 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, each.category, record_number, total_amount, total_sales | |
FROM sales_slip_10k each | |
JOIN | |
( | |
SELECT | |
category, | |
COUNT(1) AS record_number, | |
SUM(amount) total_amount, | |
SUM(amount * price) AS total_sales | |
FROM sales_slip_10k | |
GROUP BY category | |
) aggr | |
ON each.category = aggr.category | |
ORDER BY goods_id, sub_category, each.category | |
LIMIT 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment