回答

收藏

是否在INSERT / UPDATE查询中存在多个MySQL子查询?

技术问答 技术问答 273 人阅读 | 0 人回复 | 2023-09-12

我打算写以下查询:
6 i1 j/ A+ l: v, v1 U% JINSERT 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表吗?# J5 {7 N+ H3 m5 c* A
MySQL在某些情况下(如果在这个时间范围内添加新的操作),是否有可能执行两个子查询顺序?total_points和count_operations不一致?
) }* r- b4 ~3 ~7 `$ w0 i1 m                                                               
2 }4 [/ s4 I% n& _; t2 i% t& G4 D    解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则