要构建报告,我必须选择一些关于我所有客户的最后交易状态的信息。到目前为止,这是我得到的:
SELECT c.firstname, c.lastname, d.product_name, o.payment, s.name, h.date_add
FROM ps_orders o
INNER JOIN ps_order_detail d ON d.id_order = o.id_order
INNER JOIN ps_customer c ON c.id_customer = o.id_customer
INNER JOIN ps_order_history h ON o.id_order = h.id_order
INNER JOIN ps_order_state_lang s ON s.id_order_state = h.id_order_state
WHERE s.id_lang =6
GROUP BY c.id_customer
HAVING MAX(h.date_add)
对于每个客户,此查询在我需要最后一个日期时选择第一个日期(字段h.date_add )。似乎 MySQL 忽略了HAVING。
我试图进行子选择,但它也不起作用。
感谢任何答案。