我有一个表,字段为atation_x,atation_x_y,atation_z,atation_id
想用一个语句更新多行的数据,比如:
update 表 set atation_x=1 , atation_y=2 , atation_z=3 where atation_id=1
update 表 set atation_x=2 , atation_y=3 , atation_z=4 where atation_id=2
...
合成一句怎么写呢?还有,如果atation_x的是数值类型的,还用加引号么?
想用一个语句更新多行的数据,比如:
update 表 set atation_x=1 , atation_y=2 , atation_z=3 where atation_id=1
update 表 set atation_x=2 , atation_y=3 , atation_z=4 where atation_id=2
...
合成一句怎么写呢?还有,如果atation_x的是数值类型的,还用加引号么?
X Y Z ID
1 2 3 1
2 3 4 2SQL:
UPDATE atation表
set atation_x=A表.X , atation_y=A表.Y , atation_z=A表.Z
FROM atation表 INNER JOIN A表 ON atation表.ID=A表.ID
update tb set atation_x=atation_id, atation_y=atation_id+1 , atation_z=atation_id+2
如果atation_x是数值的话,就不用引号了
set atation_x = (case when atation_id = 1 then 1 when atation_id = 2 then 2 else atation_x end),
atation_y = (case when atation_id = 1 then 2 when atation_id = 2 then 3 else atation_y end),
atation_z= (case when atation_id = 1 then 3 when atation_id = 2 then 4 else atation_z end)
合成一句怎么写呢?
update 表
set atation_x = (case when atation_id = 1 then 1 when atation_id = 2 then 2 else atation_x end),
atation_y = (case when atation_id = 1 then 2 when atation_id = 2 then 3 else atation_y end),
atation_z= (case when atation_id = 1 then 3 when atation_id = 2 then 4 else atation_z end)
还有,如果atation_x的是数值类型的,还用加引号么? 不需要.楼上的大哥,atation_x=1 里的1是个变量,不一定值是多少,还需要这么麻烦先构建个表再更新么?那如果这个变量的值变化的话,怎么办呢?这个不知道问的什么,能否举例?
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试。
还是感谢高手们了。。散分吧。。