现在有这样的一张表img_style,表示图片的类型
IS_ID | IS_Name | IS_Type | IS_State | IS_Time |
1 | 生日派对 | 1 | 1 | 2016-07-26 15:15:58 |
2 | 开业年会 | 2 | 1 | 2016-07-26 15:15:58 |
3 | 婚礼 | 3 | 1 | 2016-07-26 15:15:58 |
4 | 促销 | 4 | 1 | 2016-07-26 15:15:58 |
现在要插入一条新数据,要求IS_Type也需要递增
INSERT INTO img_style (IS_Name,IS_Type,IS_State,IS_Time) VALUES ('aaaa',(SELECT COUNT(1) FROM img_style)+1,1,NOW());
报错[Err] 1093 - You can't specify target table 'img_style' for update in FROM clause
我觉得大致的意思应该是你不能调用已经在sql语句中的原表进行操作,需要新开一个临时表
修改sql语句如下
INSERT INTO img_style (IS_Name,IS_Type,IS_State,IS_Time) VALUES ('aaaa',(SELECT COUNT(1) FROM img_style a)+1,1,NOW());