如何为以下SQL查询编写GORM executeUpdate查询
UPDATE student_marks sm SET
sm.totalMarks = sm.theoryMarks + sm.homeAssignmentMarks
WHERE
sm.homeAssignmentMarks IS NOT NULL
AND sm.theoryMarks IS NOT NULL
AND sm.theoryMarks = sm.totalMarks
AND sm.examHeldIn = 6;
这里的理论标记和homeAssignmentMarks都是String。
答案 0 :(得分:0)
def map = [:]
map.examHeldInt = 6
StudentMarks.executeUpdate("""
UPDATE StudentMarks sm SET
sm.totalMarks = CAST(sm.theoryMarks AS int) + CAST(sm.homeAssignmentMarks AS int)
WHERE
sm.homeAssignmentMarks IS NOT NULL
AND sm.theoryMarks IS NOT NULL
AND sm.theoryMarks = sm.totalMarks
AND sm.examHeldIn = :examHeldIn""", map)
上面你需要将字符串视为int以便能够添加它们查找强制转换和连接