I want to get the table that represents two columns: order date and order count by specified product ID and order status. So, I should get how many orders were created in a specified date range by the product (by ID) with a specified status, for example, on-hold.
I've tried to combine several codes
SELECT DISTINCT count(p.ID) FROM wp_posts as p
WHERE p.post_type = 'shop_order' AND p.post_date BETWEEN '2021-01-01' AND '2021-01-21'
AND p.post_status IN ('wc-on-hold')
and
SELECT order_items.order_id
FROM wp_woocommerce_order_items as order_items
LEFT JOIN wp_woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
LEFT JOIN wp_posts AS posts ON order_items.order_id = posts.ID
WHERE posts.post_type = 'shop_order'
AND posts.post_status IN ('wc-on-hold')
AND order_items.order_item_type = 'line_item'
AND order_item_meta.meta_key = '_product_id'
AND order_item_meta.meta_value = '585'
but can't get the result I want.
I'm looking for a solution. Any suggestions?