我希望以下查詢將更新所有行,其中updated=0
,但它不。它只做一次更新。你能明白爲什麼嗎?爲什麼不更新所有行時應更新所有行?
UPDATE scores t1
JOIN scores t2
ON FIND_IN_SET(t1.id, t2.vals)
SET t1.total = t1.total + 1
WHERE t2.updated = 0;
表運行的查詢
"id" "total" "vals" "updated"
"1" "0" "" "0"
"2" "0" "" "0"
"3" "0" "" "0"
"4" "0" "1,2,3" "0"
"5" "0" "1,2" "0"
期望的結果
"id" "total" "vals" "updated"
"1" "2" "" "0"
"2" "2" "" "0"
"3" "1" "" "0"
"4" "0" "1,2,3" "0"
"5" "0" "1,2" "0"
之前什麼我越來越
"id" "total" "vals" "updated"
"1" "1" "" "0"
"2" "1" "" "0"
"3" "1" "" "0"
"4" "0" "1,2,3" "0"
"5" "0" "1,2" "0"
由於update scores set totals = 1 where updated = 0
更新了所有行,所以這也應該起作用。
它只更新匹配'ON'條件的行。 – Barmar
@Barmar我已經用結果更新了我的問題。它只更新一次在我的情況下,採取'4' – jmenezes