我在MySQL
中有一个表如下所示:
studentID
subjectID
anotherID
anotherID2
,AnotherID3
,studentScore
此表中有大约100M
个学生记录。
假设我将以下信息存储在两个python
列表中:
listStudentIDs
=[112335524425653]
listNewScores
=[12.76,73.2,83.893,92.3,53.6]
如果且仅当学生在listNewScores
中的分数大于其当前存储在数据库中的分数(studentScore
)时,是否可以有one query
更新所有studentScore
字段(其ID位于listStudentIDs
)的功能?
在您的示例中,它们是5个学生ID,只有4个分数需要更新。
如果要更新的学生列表不长,则可以在一个查询中进行更新,如下所示:
尽管如此,使用包含以下几个查询的SQL语句的可能性较小:
不幸的是,MySql无法处理这个问题。否则,我会一直用它!
尝试将两个列表放入临时表(studentID,studentScore)。
然后您应该能够运行一个查询来相应地更新主表。
相关问题 更多 >
编程相关推荐