我是mySQL的新手,请求帮助。我有一个sales_flat_order列,用于保存来自多个客户的订单以及sales_flat_order_status_history表,用于保存每个订单的评论(如待处理,已验证,完成等)。我正在尝试合并这两个表,但只返回订单号,我只选择已验证的最小值(状态)。但是,当我运行我的代码时,我得到重复请求我需要帮助。请参阅下面的代码。请帮忙。
SELECT DISTINCT sales_flat_order.customer_id,
MIN(sales_flat_order_status_history.entity_id) AS
entity_id,sales_flat_order_status_history.parent_id,
sales_flat_order_status_history.created_at AS order_date
FROM sales_flat_order LEFT JOIN sales_flat_order_status_history
ON sales_flat_order_status_history.parent_id = sales_flat_order.entity_id
LEFT JOIN (SELECT customer_id FROM sales_flat_order
LEFT JOIN sales_flat_order_status_history ON
sales_flat_order_status_history.parent_id = sales_flat_order.entity_id
WHERE sales_flat_order.created_at < '2013-11-30 23:00:00') AS oo ON
oo.customer_id=sales_flat_order.customer_id
WHERE ((sales_flat_order_status_history.status LIKE '%verified%' AND
sales_flat_order.created_at > '2013-11-01 00:00:00')
OR (sales_flat_order.status LIKE '%complete%' AND sales_flat_order.created_at < '2013- 11-01 00:00:00'))
AND sales_flat_order_status_history.created_at >= '2013-11-30 23:00:00'
AND sales_flat_order_status_history.created_at <= '2013-12-31 22:59:59'
AND sales_flat_order.customer_id IS NOT NULL
AND oo.customer_id IS NULL
GROUP BY sales_flat_order.entity_id