0
我有一個觸發這個update語句在我的數據庫之一:的MySQL 5.7更新錯誤:1093
UPDATE trainees
SET rsi_total = (
SELECT SUM(RsiTotal) as RsiTotal
FROM (
SELECT MAX(hours) as RsiTotal
FROM courses
LEFT JOIN do_not_add ON courses.fk_class_id = do_not_add.fk_class_id
INNER JOIN trainees ON courses.FK_TRAINEES_ID = trainees.PK_TRAINEE_ID
WHERE do_not_add.fk_class_id IS NULL
AND trainees.pk_trainee_id = new.fk_trainees_id
GROUP BY courses.FK_CLASS_ID
) courses
)
WHERE trainees.pk_trainee_id = new.fk_trainees_id
和正是我期待呢,最近我遷移我的數據庫到另一臺機器,搬運和改名幾個表和列。所以我重新寫了這個觸發器:
UPDATE main
SET rsi_total = (
SELECT SUM(RsiTotal) as RsiTotal
FROM (
SELECT MAX(completed_hrs) as RsiTotal
FROM courses
LEFT JOIN jac.do_not_add ON courses.fk_class_id = do_not_add.fk_class_id
INNER JOIN main ON courses.fk_main_id = main.pk_main_id
WHERE do_not_add.fk_class_id IS NULL
AND main.pk_main_id = new.fk_main_id
GROUP BY courses.FK_CLASS_ID
) courses
)
WHERE main.pk_main_id = new.fk_main_id
但我得到錯誤1093?我查了一下這個錯誤,它說我無法更新正在更改的表格,我不明白爲什麼舊的觸發器繼續工作,但不是這個新的?
謝謝你的鏈接,我仍然不知道如何着手解決問題。鏈接沒有提到使用SET optimizer_switch ='derived_merge = off';不知道它是什麼意思,所以更多的研究是爲了。 – Gustavo1478
順便說一下,我的舊機器運行MySQL 5.6,我的新版本正在運行5.7,顯然它改變了MySQL的功能,阻止它的工作。 – Gustavo1478
@ Gustavo1478您最後的評論強調問題來自何處。關於你以前的評論,這是很簡單:你只需要添加'SET optimizer_switch =「derived_merge = OFF」;'在查詢的開始行。 – cFreed