是否在INSERT / UPDATE查询中存在多个MySQL子查询?
技术问答
272 人阅读
|
0 人回复
|
2023-09-12
|
我打算写以下查询:
4 ?* H! ^9 m7 { a/ V! QINSERT INTO summary (user_id,total_points,count_operations)SELECT 15 AS user_id, (SELECT SUM(points) FROM operations WHERE user_id = 15) AS total_points, (SELECT COUNT(*) FROM operations WHERE user_id = 15) AS count_operationsON DUPLICATE KEY UPDATEtotal_points = VALUES(total_points),count_operations = VALUES(count_operations);整个陈述是原子吗?也就是说,MySQL(带有MyISAM内部锁定引擎)operations表吗?. t6 Q1 z b* o- f
MySQL在某些情况下(如果在这个时间范围内添加新的操作),是否有可能执行两个子查询顺序?total_points和count_operations不一致?
# J' w' j# I1 r/ ~
2 w* v1 R& Z) N6 X7 W# `% N3 X 解决方案: |
|
|
|
|
|