想请问 如果是想让数据库里的某一列数值加1 怎么写update 语句合适呢?

如题所述

1、创建测试表,create table test_update(id number);

2、插入测试数据,

insert into test_update values(1);

insert into test_update values(12);

insert into test_update values(23);

3、查询表中数据,select t.*, rowid from test_update  t

4、执行update语句,update test_update set id = id+1;

5、再次查询数据,发现数据已变化;select t.*, rowid from test_update  t

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-10-26

格式:update 表名称 set 字段名称 = 字段名称 + 1 [ where语句],具体步骤如下。

1、update 表1 set hp = isnull(hp,0) +1,update语句将此表所有行的int这一列。

2、如果有一个表的字段ID为CD一串数字,现在想要将其值顺序增加无限+1,即最后一个数字加1。

3、sql可以实现值增加了,然后进行update。

4、如果表temp有很多字段,如(aa,id,xxx,xxx,xxx),要把所有字段列出。

本回答被网友采纳
第2个回答  推荐于2017-11-26
首先,加1的列须是整型的。其实也没什么意义。

sql这样:
update 表名 set 字段=字段 + 1 where 条件;

不知楼主要实现什么样的功能呢?本回答被网友采纳
第3个回答  2013-10-11
update TableName set rowName = (rowName + 1) where row_id = ?;
第4个回答  2013-10-09
update table_name
set column_a = (select a + 10 from table_name )
where a = a
相似回答