我创建了一个查询来更新一个字段。但我需要更改最后一条记录的值。在我的ps_order_history表中有date_add列。它的类型是datetime。如果不能在 where 子句中使用 max() 函数,如何获得最后一条记录?这是我到目前为止得到的(有一些固定的参数,但这只是为了测试。我将在 PHP 代码中更改它):
UPDATE ps_order_history AS h
INNER JOIN ps_order_detail d ON d.id_order = h.id_order
INNER JOIN ps_orders o ON o.id_order = h.id_order
SET h.id_order_state = 18
WHERE d.product_name = "Academia Mastermaq"
AND o.id_customer = (
SELECT id_customer
FROM ps_customer
WHERE firstname = "Cristiano"
AND lastname = "Ferreira dos Santos"
)
AND max(h.date_add)
谢谢。