1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
select pm.meta_value /*max( CASE WHEN im.meta_key = '_product_id' and i.order_item_id = im.order_item_id THEN im.meta_value END ) as Prod_ID*/ from wp_posts as p inner join wp_postmeta as pm on p.id = pm.post_id inner join wp_woocommerce_order_items as i on p.id = i.order_id inner join wp_woocommerce_order_itemmeta as im on i.order_item_id = im.order_item_id where p.post_type = 'shop_order' AND pm.meta_key = '_billing_email' and p.post_date BETWEEN '2023-03-19 00:00:00' AND '2023-03-19 23:59:59' and p.post_status = 'wc-completed' AND i.order_item_name LIKE '%Double Chin%' group BY pm.meta_value |