How to apply filter in the report page when using SQL query
-
How can I apply a filter to the custom SQL query. The filter has to appear on the reports page. I tried using add field, but then it shows only that field and does not consider the query. The query I am trying to use is the below:
I would like to apply filter on the post_date.
SELECT
posts.id,
posts.post_date,
posts.post_status,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_first_name’ THEN meta.meta_value
END) AS shipping_first_name,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_last_name’ THEN meta.meta_value
END) AS shipping_last_name,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_address_1’ THEN meta.meta_value
END) AS shipping_address_1,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_address_2’ THEN meta.meta_value
END) AS shipping_address_2,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_city’ THEN meta.meta_value
END) AS shipping_city,
MAX(CASE
WHEN meta.meta_key = ‘_shipping_state’ THEN meta.meta_value
END) AS shipping_state,
MAX(CASE
WHEN meta.meta_key = ‘_order_shipping’ THEN meta.meta_value
END) AS order_shipping,
MAX(CASE
WHEN meta.meta_key = ‘_order_shipping_tax’ THEN meta.meta_value
END) AS order_shipping_tax,
MAX(CASE
WHEN meta.meta_key = ‘_order_tax’ THEN meta.meta_value
END) AS order_tax,
MAX(CASE
WHEN meta.meta_key = ‘_order_total’ THEN meta.meta_value
END) AS order_total,
MAX(CASE
WHEN meta.meta_key = ‘_payment_method_title’ THEN meta.meta_value
END) AS payment_method_title
FROM
wp_posts as posts LEFT OUTER JOIN wp_postmeta as meta ON posts.id = meta.post_id
WHERE
posts.post_type = ‘shop_order’
AND posts.post_date >= ‘2020-04-20’
group by posts.id,
posts.post_date,
posts.post_status
- The topic ‘How to apply filter in the report page when using SQL query’ is closed to new replies.