这适用于WordPress / Woocommerce
我正在使用此查询来抓取meta_value based
和post_ids
中的特定wp_postmeta
匹配wp_posts
SELECT meta.meta_value
FROM wp_postmeta AS meta
JOIN wp_posts AS o
ON meta.post_id = o.ID
WHERE o.post_type = 'shop_order' AND o.post_status='wc-cancelled' AND meta.meta_key='_billing_email'
ORDER BY o.post_date DESC
我的问题是,我也希望在同一查询中获得meta.meta_keys = '_billing_first_name'
和'_billing_last_name'
相同的条件。现在我必须分别得到每一行,然后将它们组合在excel表上。
有办法做到这一点吗?
答案 0 :(得分:0)
如果我理解正确,可以使用简单OR
或使用IN
SELECT meta.meta_value
FROM wp_postmeta AS meta
JOIN wp_posts AS o
ON meta.post_id = o.ID
WHERE o.post_type = 'shop_order' AND o.post_status='wc-cancelled'
AND meta.meta_key IN ('_billing_email' , '_billing_first_name', '_billing_last_name')
ORDER BY o.post_date DESC