任何人都可以告诉我以下结果应该符合标准(欢迎参考标准的正确部分)
> select * from t1;
+------+
| col1 |
+------+
| 9 |
| 8 |
| 10 |
+------+
> update t1
set col1 = col1 * 2
where col1 <= (select avg(col1) from t1);
重点是:最后一行是否得到更新,因为如果按顺序更新行并且每行重新计算平均值,它将满足条件,或者不会更新,因为此语句更改的任何数据只会是在整个语句运行后可读?
编辑
这个案子怎么样?
> 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);
解决方法
据我所知,标准(第14.11节,SQL 2003 – 基金会)对此非常清楚:
The is effectively evaluated for each row of T before any row of T is updated
(强调我的)
我对该句子的理解是在更新任何行之前评估任何条件(无论是否相关).
