You can't specify target table '表名' for update……
生活随笔
收集整理的這篇文章主要介紹了
You can't specify target table '表名' for update……
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
建表sql
DROP TABLE IF EXISTS `car`; CREATE TABLE `car` (`id` int(11) NOT NULL AUTO_INCREMENT,`type_id` int(11) NOT NULL,`name` varchar(255) DEFAULT NULL,`num` int(11) DEFAULT NULL,PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;-- ---------------------------- -- Records of car -- ---------------------------- INSERT INTO `car` VALUES ('1', '1', '張三', '3'); INSERT INTO `car` VALUES ('2', '2', '李四', '2'); INSERT INTO `car` VALUES ('3', '3', '王五', '4'); INSERT INTO `car` VALUES ('4', '4', '趙六', '1'); INSERT INTO `car` VALUES ('5', '1', '李四', '2');-- ---------------------------- -- Table structure for `car_type` -- ---------------------------- DROP TABLE IF EXISTS `car_type`; CREATE TABLE `car_type` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`money` int(11) DEFAULT NULL,PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;-- ---------------------------- -- Records of car_type -- ---------------------------- INSERT INTO `car_type` VALUES ('1', '奧迪', '300'); INSERT INTO `car_type` VALUES ('2', '奔馳', '500'); INSERT INTO `car_type` VALUES ('3', '寶馬', '350'); INSERT INTO `car_type` VALUES ('4', '大眾', '200');一條sql語句更新,將money大于200的num數量如果等于3則加3,如果等于2則加1,如果等于1則加2.
update car set num =case when num = 3 then num+3when num = 2 then num+1when num = 1 then num+2 else numend where id in ( select t.id from ( select c.id id from car c left join car_type t on c.type_id = t.id where money > 200 ) t )報錯[Err] 1093 - You can't specify target table 'car' for update in FROM clause
轉載于:https://my.oschina.net/u/2301293/blog/1931839
總結
以上是生活随笔為你收集整理的You can't specify target table '表名' for update……的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 磁盘管理深入
- 下一篇: C#/winform 窗体适应不同分辨率