首页 > 数据库 >mysql Code: 1093. You can't specify target table for update in FROM clause

mysql Code: 1093. You can't specify target table for update in FROM clause

时间:2024-05-11 10:31:18浏览次数:10  
标签:Code target 1093 new plan2version plan plan2code table null

执行如下sql会报错,大概是delete的where条件里面不能包含自身的表

delete from t_plan_new where plan2code is not null and plan2version is not null and (plan2code,plan2version) not in(select plan2code,max(plan2version) from t_plan_new group by plan2code)

 

所以用临时表

CREATE TEMPORARY TABLE IF NOT EXISTS temp_table AS
select plan2code,max(plan2version) from t_plan_new group by plan2code

然后

delete from t_plan_new where plan2code is not null and plan2version is not null and (plan2code,plan2version) not in(   select * from temp_table)

但是又发现一个问题

因为select * from temp_table里面有null所以用not in会一条都匹配不到

所以要么改成not exists取代not in

要么在not in的子查询里面加入非null判断

delete from t_plan_new where plan2code is not null and plan2version is not null and (plan2code,plan2version) not in(   select * from temp_table  where plan2code is not null)

标签:Code,target,1093,new,plan2version,plan,plan2code,table,null
From: https://www.cnblogs.com/xiaohanlin/p/18185962

相关文章

  • StarCoder2-Instruct: 完全透明和可自我对齐的代码生成
    指令微调是一种技术,它能让大语言模型(LLMs)更好地理解和遵循人类的指令。但是,在编程任务中,大多数模型的微调都是基于人类编写的指令(这需要很高的成本)或者是由大型专有LLMs生成的指令(可能不允许使用)。我们推出了一个叫做StarCoder2-15B-Instruct-v0.1的模型,这是第......
  • Codeforces 1146D Frog Jumping
    首先根据裴蜀定理,能走到的点\(x\)肯定满足\(\gcd(a,b)|x\)。于是令\(g=\gcd(a,b)\),可以考虑求解\(\lfloor\frac{m}{g}\rfloor,\frac{a}{g},\frac{b}{g}\),最后记得去判一下\([g\lfloor\frac{m}{g}\rfloor,m]\)这个区间,因为只有这个区间是不满(区间长度可能\(<g\)......
  • BIKE decode.c
    /******************************************************************************BIKE--BitFlippingKeyEncapsulationCopyright(c)2021NirDrucker,ShayGueron,RafaelMisoczki,TobiasOder,TimGueneysu,JanRichter-Brockmann.Contact:drucker.nir@g......
  • BIKE decode.h
    /******************************************************************************BIKE--BitFlippingKeyEncapsulationCopyright(c)2021NirDrucker,ShayGueron,RafaelMisoczki,TobiasOder,TimGueneysu,JanRichter-Brockmann.Contact:drucker.nir@g......
  • P6610 [Code+#7] 同余方程
    P6610[Code+#7]同余方程首先可以中国剩余定理。至于为什么\(a,b\)在满足同余条件后\(a^2+b^2\)仍然满足,是因为根据中国剩余定理的过程,会得到只有当前方程结果为\(a\)的数加起来,所以不管套什么函数都是对的。然后就是推式子了。\[\begin{aligned}ans&=\sum_{a+b\equiv......
  • Leedcode-岛屿的周长
    自己写的:classSolution:defislandPerimeter(self,grid:List[List[int]])->int:#初始化周长计数器count=0#遍历二维网格的行foriinrange(len(grid)):#遍历二维网格的列forjinrange(len(gr......
  • AtCoder Beginner Contest 318 Ex Count Strong Test Cases
    洛谷传送门AtCoder传送门首先做一些初步的观察:A和B的解法是对称的,所以A对的方案数等于B对的方案数。同时若A和B同时对则每个置换环环长为\(1\),方案数为\(n!\)。所以,若设A对的方案数为\(x\),那么答案为\(n!^2-(x-n!)-(x-n!)-n!=n!^2+n!-x\)。......
  • CF1787H Codeforces Scoreboard
    CF1787HCodeforcesScoreboard校内测试的一道题,考试时根本没动。。题面考虑\(k\)比较大的放前面肯定优,然后修门挨着放也肯定优,所以先按\(k\)排个序,然后我们就只考虑每个门修不修。设计状态\(f[i][j]\)表示前\(i\)个点,有\(j\)个门取\(b-kt\),少送回去的最少......
  • post请求下载文件,"Content-Type": "application/x-www-form-urlencoded",
    importaxiosfrom"axios";importqsfrom"qs";if(item.resourceName=="导出"){const[startTime="",endTime=""]=this.rangeTime||[];letparams={carNumber:this.carNu......
  • Topcoder SRM622-Div1-Lv2 Ethernet
    涉及知识点:图论贪心题意有一颗\(n\(\leq50)\)个节点的树,节点\(i\)的父亲为fa[i],到父亲的边的边权为dis[i],边权\(\leq500\)。现在要将每个点分配到\(k\)个连通子图中的一个,使得子图中距离最长的两个点距离小于\(maxd\),定义子图为:如果\(u\)和\(v\)都是该子图的......