SELECT wp_terms.name AS 'Exam',
(SELECT wp_postmeta.meta_value
FROM wp_postmeta
WHERE wp_postmeta.meta_key in ('_order_total')),
wp.id,
wp_woocommerce_order_itemmeta.meta_value AS 'Product Id',
f.order_item_name,
(SELECT wp_postmeta.meta_value
FROM wp_postmeta
WHERE wp_postmeta.meta_key in ('_billing_email'))
FROM wp_term_taxonomy
INNER JOIN wp_terms ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
INNER JOIN wp_woocommerce_order_itemmeta ON wp_woocommerce_order_itemmeta.meta_value = wp_term_relationships.object_id
INNER JOIN (SELECT f.order_item_id,
f.order_id,
f.order_item_name
FROM wp_woocommerce_order_items f) f ON f.order_item_id = wp_woocommerce_order_itemmeta.order_item_id
INNER JOIN wp_postmeta ON wp_postmeta.post_id = f.order_id
INNER JOIN (SELECT wp.id,
FROM wp_posts wp
INNER JOIN wp_postmeta wm ON wp.id = wm.post_id
WHERE wp.post_type = 'shop_order'
AND wp.post_status = 'wc-completed' AND wm.meta_key = '_completed_date') wp ON wp.id = wp_postmeta.post_id
WHERE wp_term_taxonomy.taxonomy = 'product_cat'
AND wp_term_taxonomy.term_id IN (2825,2829,2833,2837,2844,2851,2847)
AND wp_woocommerce_order_itemmeta.meta_key = '_product_id'
AND wp_postmeta.meta_key IN ('_order_total','_billing_email')
上述sql查詢拋出子查詢返回多個行錯誤。我希望列中的帳單郵寄地址和另一列中的訂單總額。怎麼做?sql子查詢返回多於1行錯誤
是_billing_email和_order_total只有1行嗎?或者您想要將所有這些行組合爲每個選定記錄的1個值,或許您可以將wp_postmeta的左連接而不是將其放入選擇, for ex: SELECT ...,_billing_email,.... FROM .. ..... LEFT JOIN(SELECT STRING_aggregate_function(wp_postmeta.meta_value,',')as _billing_email WHERE wp_postmeta.meta_key in('_billing_email'))ON id = id .... –
感謝您的回覆,_billing_email和_order_total是在同一個表中具有不同元值的不同元鍵。我想要兩個不同列的元值。 –
Oracle或mysql? – Aleksej