update c_visitor set pv_num=pv_num+1
where id=(select max(id)
from c_visitor
where c_info_id =1
and curUrl='http://127.0.0.1:8081/hboys');
我想更新c_visitor,根据 c_info_id =1 and curUrl='http://127.0.0.1:8081/hboys' 的条件,可是报错
sql执行错误 # 1093 .从数据库的响应:
you can't specify target table 'c_visitor; for update in from clause如果我单独执行,是可以的
但是我想合并到一起
不知道怎么办
请各位高手指点
where id=(select max(id)
from c_visitor
where c_info_id =1
and curUrl='http://127.0.0.1:8081/hboys');
我想更新c_visitor,根据 c_info_id =1 and curUrl='http://127.0.0.1:8081/hboys' 的条件,可是报错
sql执行错误 # 1093 .从数据库的响应:
you can't specify target table 'c_visitor; for update in from clause如果我单独执行,是可以的
但是我想合并到一起
不知道怎么办
请各位高手指点
当在进行更新的时候,表就被锁定这时是不允许进读取操作的.而你在子查询与更新表使用的是同一个表,所以出了问题.所以只能分开写了,max(id)存在一个变量里,然后再进行更新
能把表结构给贴出来吗?
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| Id | int(11) | NO | PRI | NULL | auto_increment |
| c_info_id | int(11) | NO | | | |
| user_id | int(11) | NO | | | |
| c_day_id | int(11) | NO | | | |
| Visit_Date | datetime | YES | | NULL | |
| Ip | varchar(64) | YES | | NULL | |
| Address | varchar(64) | YES | | NULL | |
| System | varchar(32) | YES | | NULL | |
| Browser | varchar(32) | YES | | NULL | |
| Screen | varchar(16) | YES | | NULL | |
| Referer | varchar(128) | YES | | NULL | |
| curURL | varchar(128) | YES | | NULL | |
| pv_num | int(11) | YES | | 1 | |
+------------+--------------+------+-----+---------+----------------+