Last active
May 13, 2021 08:22
-
-
Save connorhu/61295c8d02187d678ae5bb59838800a2 to your computer and use it in GitHub Desktop.
WP Gists
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
SET @prefix = 'wp_'; | |
SET @date_from = '2020-01-01'; | |
SET @date_to = '2020-12-31'; | |
SET @query = CONCAT('SELECT sum(woim.meta_value) number_of_item_sold, woi.order_item_name | |
FROM ', @prefix, 'woocommerce_order_itemmeta as woim | |
LEFT JOIN ', @prefix, 'woocommerce_order_items as woi ON woi.order_item_id = woim.order_item_id | |
LEFT JOIN ', @prefix, 'posts as p ON woi.order_id = p.ID | |
WHERE woim.meta_key = \'_qty\' | |
AND p.post_status = \'wc-completed\' | |
AND p.post_date BETWEEN \'', @date_from, '\' AND \'', @date_to, '\' | |
GROUP BY woi.order_item_name | |
ORDER BY number_of_item_sold DESC'); | |
PREPARE stmt FROM @query; | |
EXECUTE stmt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment