从woocommerce数据库获取销售产品和库存

时间:2017-10-19 09:14:50

标签: mysql sql woocommerce

来自woocommerce网站的

尝试进行查询,该查询给出了产品清单的结果,包括库存和销售数量。但没有运气.. 代码在这里

    select *, SUM(`wp_woocommerce_order_itemmeta`.`meta_value`) as total from wp_aproduts 
    LEFT JOIN       
        (select *, SUM(`wp_woocommerce_order_itemmeta`.`meta_value`) as total 
            from wp_woocommerce_order_items 

            JOIN wp_woocommerce_order_itemmeta 
                ON wp_woocommerce_order_items.order_item_id = wp_woocommerce_order_itemmeta.order_item_id 

                WHERE wp_woocommerce_order_itemmeta.meta_key = '_qty' GROUP BY wp_woocommerce_order_items.order_item_name
        ) as Z

        ON `wp_aproduts`.`product_name` = wp_woocommerce_order_items.order_item_name GROUP BY `wp_aproduts`.`product_name` 

任何人都可以帮忙......

我的英语很差。

1 个答案:

答案 0 :(得分:0)

具有销售记录的woocommerce产品库存..

select * from wp_aproduts 
    LEFT JOIN       
        (select wp_woocommerce_order_itemmeta.order_item_id, SUM(wp_woocommerce_order_itemmeta.meta_value) AS SALE, `wp_woocommerce_order_items`.`order_item_name` as item, order_item_name
    from wp_woocommerce_order_items 

    JOIN wp_woocommerce_order_itemmeta 
        ON wp_woocommerce_order_items.order_item_id = wp_woocommerce_order_itemmeta.order_item_id 

        WHERE wp_woocommerce_order_itemmeta.meta_key = '_qty' GROUP BY wp_woocommerce_order_items.order_item_name
        ) as Z

        ON `wp_aproduts`.`product_name` = Z.order_item_name GROUP BY `wp_aproduts`.`product_name`
ORDER BY `wp_aproduts`.`sl_no` ASC