总结自定义查询(WooCommerce)

时间:2017-09-11 10:49:45

标签: mysql wordpress woocommerce

以下查询为woocommerce订单中的每个产品返回一行,其中包含订单详情,line_total(已售出价格)和所有者。

owner是一个自定义字段,告诉我谁是产品的供应商,我使用子查询得到它的值,如下所示:

SELECT *, 
   (SELECT meta_value FROM wp_woocommerce_order_itemmeta meta WHERE order_item_id = items.order_item_id AND meta.meta_key LIKE '_product_id') AS product_id, 
   (SELECT meta_value FROM wp_woocommerce_order_itemmeta meta WHERE order_item_id = items.order_item_id AND meta.meta_key LIKE '_line_total') AS line_total, 
   (SELECT meta_value FROM wp_postmeta WHERE meta_key = 'product_owner' AND post_id = product_id) AS owner
FROM wp_woocommerce_order_items items, wp_posts orders
WHERE orders.ID = items.order_id
HAVING owner LIKE 'someownername'

上面的查询工作得很好,我需要做的是总结上述查询的输出,只显示以下内容:

Year Month, Total Sales
2017 January, 3211
2018 February, 4553
...

orders.post_date字段应该用于获取年份和月份,而line_total应该用于获取付费摘要。

任何帮助?

0 个答案:

没有答案