mysql - Creating WooCommerce Analytical report with SQL -
I have recently moved to WooCommerce platform and need to create mysql in SQL to run my own analytical report is. For example, I need a report that shows the total number per sale per country in the last 30 days. I searched the table like 'wp_posts', 'wp_postmeta', and found that most of the fields and orders are record-based, not column-based, which makes SQL a little more challenging. Lastly, SQL is created by me, and it is expected that it can be used by other WooCommerce users, which is analytical outside box.
Will be useful for solutions or not wanting to use custom reporting.
select sku, count (1) wp_woocommerce_order_items from oi, - woocommerce use posts to keep metadata at wp_postmeta at command, - - Order table p wp_posts, we use this table filter To get the PM1 wp_postmeta threshold order - we use this table again to get shipping country information wp_woocommerce_order_itemmeta OIM, - to obtain the product ID from this table order, p.id product_id form meta_value sku as wp_posts p, wp_postmeta At where post_type = 'product' and post_status = 'published Use 'ray' and meta_key = '_kquu' and p (select id = sku_table as pm.post_id) - Publish products from the building ski ski table product id and sku ou oim.meta_value = sku_table.product_id and oi. Defines the relationship between order_id = p.id and p.id = pm.post_id and pm.meta_key = '_ paid_date' and here we ensure that the order was completed p.id = pm1.post_id And order_item_type = create 'LINE_ITEM' and - not only get line items but tax or shipping oi.order_item_id = oim.order_item_id and oim.meta_key = '_product_id' and POST_DATE & Gt; '2014-01-01' and - by limited sku order country group - shipping country pm1.meta_value = 'US' - report date pm1.meta_key = '_ shipping_country' and borders sku;
Comments
Post a Comment