SQL标准在UPDATE中对“依赖”条件的说法是什么?
发布时间:2021-03-30 18:28:15  所属栏目:MsSql  来源:互联网 
            导读:任何人都可以告诉我以下结果应该符合标准(欢迎参考标准的正确部分) select * from t1;+------+| col1 |+------+| 9 || 8 || 10 |+------+ update t1 set col1 = col1 * 2 where col1 = (select avg(col1) from t1); 重点
                
                
                
            | 
                         任何人都可以告诉我以下结果应该符合标准(欢迎参考标准的正确部分) > 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 – 基金会)对此非常清楚:
 (强调我的) 我对该句子的理解是在更新任何行之前评估任何条件(无论是否相关). (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
