— get orders information
SELECT DISTINCT pm.meta_value AS user_id, pm.post_id AS order_id
FROM wp_z8tmn5qbx1_postmeta AS pm
LEFT JOIN wp_z8tmn5qbx1_posts AS p
ON pm.post_id = p.ID
LEFT JOIN wp_z8tmn5qbx1_postmeta AS pm2
ON p.ID = pm2.post_id
WHERE p.post_type = 'shop_order'
AND pm.meta_key = '_customer_user'
AND pm2.meta_key IN ( '_paid_date', '_paid_date', '_date_completed', '_completed_date' )
AND pm2.meta_value != ''
ORDER BY pm.meta_value ASC, pm.post_id DESC
'wc-completed'
SELECT distinct o.order_item_name, o.order_id, os., o.,om., u.
FROMwp_z8tmn5qbx1_wc_order_stats
os
LEFT JOIN wp_z8tmn5qbx1_woocommerce_order_items
o ON os.order_id = o.order_id
LEFT JOIN wp_z8tmn5qbx1_woocommerce_order_itemmeta
om ON o.order_item_id = om.order_item_id ,
wp_z8tmn5qbx1_users u
where o.order_id
in (
SELECT DISTINCT pm.post_id AS order_id
FROM wp_z8tmn5qbx1_postmeta AS pm
LEFT JOIN wp_z8tmn5qbx1_posts AS p
ON pm.post_id = p.ID
LEFT JOIN wp_z8tmn5qbx1_postmeta AS pm2
ON p.ID = pm2.post_id
WHERE p.post_type = ‘shop_order’
AND pm.meta_key = ‘_customer_user’
AND pm2.meta_key IN ( ‘_paid_date’, ‘_paid_date’, ‘_date_completed’, ‘_completed_date’ )
AND pm2.meta_value != ”
ORDER BY pm.meta_value ASC, pm.post_id DESC
)
and u.id= os.customer_id