zoukankan      html  css  js  c++  java
  • sql 语句系列(删库跑路系列)[八百章之第七章]

    前言

    最开心的章节,没有之一。

    删除违反参照完整性的记录

    EMP 是员工表,DEPT 是部门表 DEPTNO是部门编号

    delete from EMP where not exists (
    select null from  DEPT where EMP.DEPTNO=DEPT.DEPTNO 
    )
    
    delete from EMP where DEPTNO not in(
    select DEPTNO from DEPT
    )
    

    删除重复数据

    删除名字相同的员工:

    delete from EMP where
    
    EMPNO not in(select MIN(EMPNO) from EMP group by ENAME)
    

    原理很简单,保留ENAME 相同的一项即可。

    删除被其他表参照的记录

    这里面的意思,不是说因为一个表是另外一张表的外键,而无法删除。
    而是说,根据一张表来删除另外一张表。
    dept_accidents 是一张部门发生事故的表

    select * from dept_accidents
    

    现在有一个需求,就是删除出现3次事故的部门的员工删除。

    delete from EMP
    where DEPTNO in(select deptno from dept_accidents group by deptno having count(*)>=3)
    
  • 相关阅读:
    母函数
    匈牙利算法
    AC 自动机
    MFC Invalidate闪屏问题
    求解x=a^b(mod m)
    Millar_rabin和Pollard_Rho
    图论入门算法理解
    Numpy 库常用函数大全
    Linux 系统中“|”管道的作用是什么
    win10 万能修复公式
  • 原文地址:https://www.cnblogs.com/aoximin/p/12559928.html
Copyright © 2011-2022 走看看