您好,欢迎来到好走旅游网。
搜索
您的当前位置:首页MySQL的Update语句Set顺序问题

MySQL的Update语句Set顺序问题

来源:好走旅游网

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 1. 测试一 create table test(id int, tag int, num int); insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3); update test set tag = 4, num=case when tag=4 then 4 else 3 end

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

  1. 测试一 create table test(id int, tag int, num int);

  insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3);

  update test set tag = 4, num=case when tag=4 then 4 else 3 end where tag=3;

  select * from test;

  (1)sqlserver2014的结果:

  (2)MySQL的结果:

  2. 测试二:更换set语句的顺序 create table test(id int, tag int, num int);

  insert into test (id, tag, num) values(1, 1, 1), (2,2, 2), (3,3,3);

  update test set num=case when tag=4 then 4 else 3 end, tag = 4 where tag=3;

  select * from test;

  (1)sqlserver2014的结果:

  (2)MySQL的结果

  MySQL的update语句,set列的顺序是有关系的,后面列的计算是以前面列的结果为基础的,即从左向右评估;

  (2)SQLServer的update语句,set的顺序无关,所有的更改都是基于之前取出的快照;

Copyright © 2019- haog.cn 版权所有 赣ICP备2024042798号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务