MySQL避免重复值

时间:2015-05-27 15:06:13

标签: mysql select join

我使用下面的查询列出包含4个或更多案例SKU的订单。一旦找到这些订单,我不想重复customer_email。

当前输出示例:

Order ID    | customer_email    | total_cases_invoiced
5           | this@that.com     | 6
45          | email1@here.com   | 4
32          | email1@here.com   | 7
23          | email1@here.com   | 5
28          | another@email.com | 10

期望的输出示例:

Order ID    | customer_email    | total_cases_invoiced
5           | this@that.com     | 6
45          | email1@here.com   | 4
28          | another@email.com | 10

当前查询:

SELECT 
    *, customer_email, SUM(qty_invoiced) AS total_cases_invoiced
FROM
    mg_sales_flat_order_item
        JOIN
    mg_sales_flat_order ON mg_sales_flat_order.entity_id = mg_sales_flat_order_item.order_id
WHERE
    (mg_sales_flat_order_item.sku LIKE '%A'
        OR mg_sales_flat_order_item.sku LIKE '%F'
        OR mg_sales_flat_order_item.sku LIKE '%B'
        OR mg_sales_flat_order_item.sku LIKE '%C'
        OR mg_sales_flat_order_item.sku LIKE '%FP'
        OR mg_sales_flat_order_item.sku LIKE '%AP')
        AND row_total != 0
GROUP BY order_id
HAVING SUM(qty_invoiced) >= 4
ORDER BY customer_email DESC

1 个答案:

答案 0 :(得分:0)

您是否尝试将此类emcustomer_email一起分组?

customer_id