【发布时间】:2021-02-23 14:01:50
【问题描述】:
我遇到了一个问题,我的第一个查询 (SELECT) 工作正常,但是当我尝试执行我的第二个查询 (UPDATE) 时出现错误。有人可以帮我知道我在这里做错了什么吗?
QUERY 1:
WITH res AS (
SELECT str.request_id as requestID, str.type as incorrectType, TxType.utType as correctType
FROM x str
JOIN (
SELECT tr.request_id, ut.type AS utType
FROM x tr
JOIN y tc ON tr.request_id = tc.request_id
JOIN z ut ON tc.transaction_id = ut.id
) AS TxType ON str.request_id = TxType.request_id
WHERE str.type != TxType.utType
AND str.application = 'sample' LIMIT 1
)
SELECT * FROM x tr_req
JOIN res AS re ON re.requestID = tr_req.request_id
WHERE tr_req.type != re.correctType;
RESULT : SUCCESS
QUERY : 2
WITH res AS (
SELECT str.request_id as requestID, str.type as incorrectType, TxType.utType as correctType
FROM x str
JOIN (
SELECT tr.request_id, ut.type AS utType
FROM x tr
JOIN y tc ON tr.request_id = tc.request_id
JOIN z ut ON tc.transaction_id = ut.id
) AS TxType ON str.request_id = TxType.request_id
WHERE str.type != TxType.utType
AND str.application = 'sample' LIMIT 1
)
UPDATE x tr_req
JOIN res AS re ON re.requestID = tr_req.request_id
SET tr_req.type = re.correctType
WHERE tr_req.type != re.correctType;
RESULT : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE x tr_req
【问题讨论】:
-
谢谢@P.Salmon,我需要一个限制。有超过 90 万条记录需要更新。我需要以几千个批次执行此操作,以确保它不会超时。
-
关于分块的更多信息:mysql.rjweb.org/doc.php/deletebig#deleting_in_chunks(这些原则适用于 UPDATE。)
标签: mysql select sql-update mariadb mysql-error-1064