Last active
August 29, 2015 14:08
-
-
Save Gabelbombe/40f0ca815ddec5576420 to your computer and use it in GitHub Desktop.
Displays promotion name, how many orders promo was applied to, percentage of those orders and the average total of those orders.
This file contains hidden or 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
CREATE VIEW promotions AS | |
SELECT 'Full Price' AS 'Promotion Name' | |
, COUNT(entity_id) AS '# of Orders' | |
, CONCAT(ROUND( | |
(((SELECT COUNT(b.entity_id) FROM sales_flat_order b WHERE b.applied_rule_ids IS NULL) | |
/ (SELECT COUNT(entity_id) FROM sales_flat_order a)) * 100), 1), '%') AS '% of Orders' | |
, ROUND(AVG(subtotal), 2) AS 'Avg. Total' | |
FROM sales_flat_order | |
WHERE applied_rule_ids IS NULL | |
UNION ALL | |
SELECT sr.name AS 'Promotion Name' | |
, (SELECT COUNT(entity_id) FROM sales_flat_order WHERE applied_rule_ids = sr.rule_id) '# of Orders' | |
, CONCAT(ROUND( | |
(((SELECT COUNT(b.entity_id) FROM sales_flat_order b WHERE b.applied_rule_ids = sr.rule_id) | |
/ (SELECT COUNT(entity_id) FROM sales_flat_order a)) * 100), 1), '%') AS '% of Orders' | |
, ROUND(AVG(sfo.subtotal), 2) AS 'Avg. Total' | |
FROM salesrule sr | |
, salesrule_coupon src | |
, sales_flat_order sfo | |
WHERE sr.rule_id = src.rule_id AND sr.rule_id = sfo.applied_rule_ids | |
GROUP BY sr.rule_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: