1、执行sql语句报上面的错误:

 DELETE
FROM
db_student
WHERE
RowGuid IN ( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > )
AND ID NOT IN ( SELECT MAX( ID ) AS id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > )

报错如下所示
You can't specify target table 'xxx' for update in FROM clause。

原因:因为在MYSQL里,不能先select一个表的记录,在按此条件进行更新和删除同一个表的记录。

详细参考:https://blog.csdn.net/h996666/article/details/81699255

 SELECT *
FROM
db_student
WHERE
RowGuid IN (
SELECT
aa.RowGuid
FROM
( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) aa
)
AND ID NOT IN (
SELECT
t.id
FROM
( SELECT MAX( ID ) as id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) t
) DELETE
FROM
db_student
WHERE
RowGuid IN (
SELECT
aa.RowGuid
FROM
( SELECT RowGuid FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) aa
)
AND ID NOT IN (
SELECT
t.id
FROM
( SELECT MAX( ID ) as id FROM db_student WHERE age = GROUP BY RowGuid HAVING count( * ) > ) t
)

待续......

You can't specify target table 'xxx' for update in FROM clause的更多相关文章

  1. 错误:You can't specify target table 'xxx' for update in FROM clause的解决

    问题: 今天在MySQL数据库删除重复数据的时候遇到了一个问题.如下脚本: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM t ...

  2. 关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug

    不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过: , notice_code ) a) ; 本地 ...

  3. mysql You can't specify target table 'xxx' for update in FROM clause

    含义:您不能在子句中为更新指定目标表'xxx'. 错误描述:删除语句中直接含select,如下: DELETE FROM meriadianannotation WHERE SeriesID IN ( ...

  4. mysql You can't specify target table 'xxx' for update in FROM clause的解决

    DELETE from sp_goodscontent where goodsId in (SELECT t.goodsId from ( SELECT goodsId FROM sp_goodsco ...

  5. django.db.utils.OperationalError: (1093, "You can't specify target table 'xxx' for update in FROM clause")

    这个错误的意思是,不能在update某张表的where条件中,再次select这张表的某些值作为筛选条件,比如: update message set content = "hello&qu ...

  6. You can't specify target table 'a' for update in FROM clause

    项目中有一个功能变动上线,其中有一张表ttt的字段cc,历史数据需要处理,把字段cc中为'xxx'的值替换为'yyy'. 表A结构如下: CREATE TABLE `ttt` ( `id` bigin ...

  7. mysql中更新或者删除语句中子语句不能操作同一个表You can't specify target table 'test' for update in FROM clause

    问题描述:有个数据表test,有个字段value,如下 mysql> select * from test;+----+------------------------------------+ ...

  8. mysql的一个特殊问题 you can't specify target table 'cpn_regist' for update in FROM clause

    今天在操作数据库的时候遇到了一个问题,sql语句如下: UPDATE cpn_yogurt_registration SET dep1Name = '1' WHERE `key` in  (SELEC ...

  9. Mysql update in报错 [Err] 1093 - You can't specify target table 'company_info' for update in FROM clause

    Mysql update in报错 解决方案: [Err] 1093 - You can't specify target table 'company_info' for update in FRO ...

随机推荐

  1. 一张图搞清楚PMBOK所有过程的使用

      很多参加PMP培训的学员大概都会有一个感受,上课时似乎每个知识点都听懂了,大的知识框架也弄明白了,但是所有这些串起来在实践中怎么用呀!说的再直接一点,在考试的时候这些过程和活动是以怎样的逻辑来应用 ...

  2. Linux 开发板网络设置

    改动IP地址步骤: ①改动/etc/eth0-setting 命令:vi /etc/eth0-setting ②改动对应的信息.最后:wq退出 ③重新启动eth0 命令:/etc/init.d/ifc ...

  3. U盘容纳不了大于4G的文件比如ISO文件咋办?

    格式化U盘成NTFS格式就行了,不这么做8,16,32G Upan都容纳不下来.

  4. BZOJ 题目1036: [ZJOI2008]树的统计Count(Link Cut Tree,改动点权求两个最大值和最大值)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 8421  Solved: 3439 [Submi ...

  5. Desktop Management Interface & System Management BIOS

    http://en.wikipedia.org/wiki/Desktop_Management_Interface Desktop Management Interface From Wikipedi ...

  6. JavaScript 模拟键盘事件

    JavaScript 模拟键盘事件和鼠标事件(比如模拟按下回车等) 2016年09月08日 15:23:25 神秘_博士 阅读数:41158 标签: javascript鼠标键盘事件模拟更多 个人分类 ...

  7. navicat-premium11.1.6 x64关键

    Navicat Premium version patch   11.2.16.0 >navicat.exe0000000001CECCBC:80->C60000000001CECCBD: ...

  8. busybox 终端支持 ctrl-r

    Busybox Settings ---> Busybox Library Tuning ---> [*] History saving [ ] Save history on shell ...

  9. HDOJ_1000

    #include int main() { int i, j; while(scanf("%d%d", &i, &j) == 2) printf("%d\ ...

  10. 解决gradle多模块依赖在Idea中能运行,gradle build失败的问题。

    最近需要初始化一个SpringBoot新项目遇到一个问题就是:项目中有多个子模块,使用gradle依赖管理成功. 项目结构如下: project --module1     --module2我的mo ...