任何人都可以告诉我以下结果应该符合标准(欢迎参考标准的正确部分)
> select * from t1;
+------+
| col1 |
+------+
| 9 |
| 8 |
| 10 |
+------+
> update t1
set col1 = col1 * 2
where col1 <= (select avg(col1) from t1);
Run Code Online (Sandbox Code Playgroud)
重点是:最后一行是否得到更新,因为如果按顺序更新行并且每行重新计算平均值,它将满足条件,或者不会更新,因为此语句更改的任何数据只会是在整个语句运行后可读?
编辑 这个案子怎么样?
> select * from t1;
+------+------+
| col1 | col2 |
+------+------+
| 9 | 1 |
| 8 | 2 |
| 10 | 2 |
+------+------+
> update t1 p1
set col1 = col1 * 2
where col1 <= (select avg(col1)
from t1
where col2=p1.col2);
Run Code Online (Sandbox Code Playgroud)
小智 4
据我所知,标准(第 14.11 章,SQL 2003 - 基础)对此非常清楚:
在更新 T 的任何行之前,对 T 的每一行进行有效评估
(强调我的)
我对这句话的理解是,在更新任何行之前,都会评估任何条件(无论是否相关)。