我正在尝试让子查询的WHERE部分在下面工作。我可以看到'where event_id = ..'是不明确的,因为父查询正在查看同一个表。
甚至可以在同一个表子查询中使用WHERE吗?
UPDATE tickets SET tickets.ticket_number = (
SELECT max_ticket
FROM (
SELECT (MAX(ticket_number)+1) AS max_ticket
FROM tickets
WHERE event_id=10045
)
AS sub_table
)
WHERE ticket_id=68
任何帮助都非常感激。
答案 0 :(得分:3)
可能尝试将其作为联接
UPDATE tickets a
INNER JOIN
(
SELECT (MAX(ticket_number)+1) AS max_ticket
FROM tickets
WHERE event_id = 10045
) b
SET a.ticket_number = b.max_ticket
WHERE a.ticket_id = 68