字段累计 在mysql下写一个储存过程,这个储存过程只做一件事,就是从一张表里的一个字段A取出一个值1,然后加1再放回去,那此时A字段的值变成2。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 update 一张表 set 字段A=字段A+1 有无唯一标识的字段?比如 IDupdate TT set 字段A=字段A+1 WHERE ID=1 读A表中的A字段加1等于C,然后更新B表中的B字段,将C值赋于B A表中有几条记录?B表中有几条记录? (不要高估你的汉语表达能力或者我的汉语理解能力) 建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。 参考一下这个贴子的提问方式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) 这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。 贴记录及要求结果出来看看,两表是否有相同的KEY字段 DROP TABLE IF EXISTS `times`;CREATE TABLE `times` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `date1` timestamp NULL DEFAULT NULL, `date2` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `fild` int(11) DEFAULT NULL, PRIMARY KEY (`Id`)) DROP TABLE IF EXISTS `test`;CREATE TABLE `test` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `names` varchar(50) DEFAULT NULL, `types` int(11) DEFAULT NULL, PRIMARY KEY (`Id`)) ENGINE=MyISAM DEFAULT CHARSET=gb2312;INSERT INTO `times` VALUES (1,'2010-05-13 14:34:16','2010-05-13 11:42:06',1);insert into test values(1,'book',1);要读times的fild字段值,读出来以后加1,然后更新到test的types字段值更新后的test表1 book 2 已达到你的要求。update times,testset times.fild=times.fild+1,test.types=times.fild+1;mysql> select * from times;+----+---------------------+---------------------+------+| Id | date1 | date2 | fild |+----+---------------------+---------------------+------+| 1 | 2010-05-13 14:34:16 | 2010-05-13 11:42:06 | 1 |+----+---------------------+---------------------+------+1 row in set (0.00 sec)mysql> select *from test;+----+-------+-------+| Id | names | types |+----+-------+-------+| 1 | book | 1 |+----+-------+-------+1 row in set (0.00 sec)mysql> update times,test -> set times.fild=times.fild+1,test.types=times.fild+1;Query OK, 2 rows affected (0.06 sec)Rows matched: 2 Changed: 2 Warnings: 0mysql> select * from times;+----+---------------------+---------------------+------+| Id | date1 | date2 | fild |+----+---------------------+---------------------+------+| 1 | 2010-05-13 14:34:16 | 2010-05-13 11:42:06 | 2 |+----+---------------------+---------------------+------+1 row in set (0.00 sec)mysql> select *from test;+----+-------+-------+| Id | names | types |+----+-------+-------+| 1 | book | 2 |+----+-------+-------+1 row in set (0.00 sec)mysql> MySQL多字段条件下特定字段判断问题。 大量结构相同数据库表的合并 sql语句中password句的困惑,求高手解答 关于mysql中的日期问题 JDBC连接MySQL出现的错误,希望能有人指点! 我在My.ini里加了支持gbk后打开页面提示缺少gbk.conf文件 在WIN2000 server中安装了mysql,想要卸载它,但在卸载它之后,发现服务中还有mysql项。 求解答:MySQL图状结构的表的遍历问题 mysql存储emoji表情问题 mysql如何将字符串和函数结果拼接在一起?? 求一复杂sql语句 菜鸟MySql安装问题
update TT set 字段A=字段A+1 WHERE ID=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)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
DROP TABLE IF EXISTS `times`;
CREATE TABLE `times` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`date1` timestamp NULL DEFAULT NULL,
`date2` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`fild` int(11) DEFAULT NULL,
PRIMARY KEY (`Id`)
) DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`Id` int(11) NOT NULL AUTO_INCREMENT,
`names` varchar(50) DEFAULT NULL,
`types` int(11) DEFAULT NULL,
PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=gb2312;INSERT INTO `times` VALUES (1,'2010-05-13 14:34:16','2010-05-13 11:42:06',1);
insert into test values(1,'book',1);
要读times的fild字段值,读出来以后加1,然后更新到test的types字段值
更新后的test表
1 book 2
set times.fild=times.fild+1,test.types=times.fild+1;mysql> select * from times;
+----+---------------------+---------------------+------+
| Id | date1 | date2 | fild |
+----+---------------------+---------------------+------+
| 1 | 2010-05-13 14:34:16 | 2010-05-13 11:42:06 | 1 |
+----+---------------------+---------------------+------+
1 row in set (0.00 sec)mysql> select *from test;
+----+-------+-------+
| Id | names | types |
+----+-------+-------+
| 1 | book | 1 |
+----+-------+-------+
1 row in set (0.00 sec)mysql> update times,test
-> set times.fild=times.fild+1,test.types=times.fild+1;
Query OK, 2 rows affected (0.06 sec)
Rows matched: 2 Changed: 2 Warnings: 0mysql> select * from times;
+----+---------------------+---------------------+------+
| Id | date1 | date2 | fild |
+----+---------------------+---------------------+------+
| 1 | 2010-05-13 14:34:16 | 2010-05-13 11:42:06 | 2 |
+----+---------------------+---------------------+------+
1 row in set (0.00 sec)mysql> select *from test;
+----+-------+-------+
| Id | names | types |
+----+-------+-------+
| 1 | book | 2 |
+----+-------+-------+
1 row in set (0.00 sec)mysql>