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查询抛出子查询返回多行错误。我希望列中的帐单地址和另一列中的订单总数。怎么做?
答案 0 :(得分:0)
正如vims所说,你在wp_postmeta的2个子选择中有多行。 事实上,你不会通过id或类似的东西加入它们,例如
SELECT wp_postmeta.meta_value
FROM wp_postmeta
WHERE wp_postmeta.meta_key in ('_order_total')
将使用key =' _order_total'
返回数据库中的所有行同样适用于
SELECT wp_postmeta.meta_value
FROM wp_postmeta
WHERE wp_postmeta.meta_key in ('_billing_email'))
所以,你应该在一些id上添加一个join子句给它们。 对不起,我不是WP和\或WooCommerce的专家,所以我不能给你一个关于哪个领域使用的提示。
此外,您应该将这些子选择放在FROM和WHERE部分或您的选择中。选择列表中的子选择不是一个好习惯。
答案 1 :(得分:0)
子查询不仅限于所讨论的post_id
。因此,您获得所有帖子的order_totals
。在每个子查询中添加这样的内容:
AND f.order_id = post_id
答案 2 :(得分:-1)
compute geometric measures