所有资金为null的字段,值改为3000
所以文员资金加2000
update tablexxx set 资金
= 3000 where 资金
is null;
update tablexxx set 资金
= 资金
+ 2000 where 岗位
= ‘文员’;
################首先创建一个表用于测试#######################################
mysql> CREATE TABLE `test` (
-> `id` int(10) NOT NULL AUTO_INCREMENT,
-> `NAME` varchar(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
-> `level` int(10) NOT NULL,
-> `coin` int(32),
-> PRIMARY KEY (id)
-> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into test(name,level) values('aa',10); //插入数据
Query OK, 1 row affected (0.01 sec)
mysql> insert into test(name,level,coin) values('ab',20,100);
Query OK, 1 row affected (0.01 sec)
mysql> select * from test; //coin字段未插入数据默认为null
+----+------+-------+------+
| id | NAME | level | coin |
+----+------+-------+------+
| 1 | aa | 10 | NULL |
| 2 | ab | 20 | 100 |
+----+------+-------+------+
2 rows in set (0.00 sec)
mysql> select * from test where coin is null; //查询出coin字段为null的数据
+----+------+-------+------+
| id | NAME | level | coin |
+----+------+-------+------+
| 1 | aa | 10 | NULL |
+----+------+-------+------+
1 row in set (0.00 sec)
mysql> select * from test where coin is not null; //查询出coin字段不为null的数据
+----+------+-------+------+
| id | NAME | level | coin |
+----+------+-------+------+
| 2 | ab | 20 | 100 |
+----+------+-------+------+
1 row in set (0.00 sec)