zoukankan      html  css  js  c++  java
  • mysql delete

    # 删除10部门中 工龄超过20年的员工
    delete from t_emp
    where deptno = 10 and DATEDIFF(NOW(),hiredate)/365 >= 20


    #删除20部门中工资最高的员工记录
    delete from t_emp
    where deptno = 20
    ORDER BY sal + IFNULL(comm,0) DESC
    limit 1

    # 删除 SALES 部门和该部门的全部员工记录
    DELETE e,d
    from t_emp e join t_dept d
    on e.deptno = d.deptno
    where d.dname = 'SALES'

    # 删除每个低于部门平均底薪的员工记录
    delete e from t_emp e
    join (
    select deptno, avg(sal + IFNULL(comm,0)) sal from t_emp
    GROUP BY deptno) as t
    on e.deptno = e.deptno and e.sal < t.sal

    # 删除员工king 和他的直接下属员工记录
    delete e from t_emp e
    join
    (select empno from t_emp where ename = 'KING') as t on t.empno = e.mgr or e.empno = t.empno

    # 删除SALES部门的员工,以及没有部门的员工 

    delete e
    from t_emp e
    left join t_dept d on e.deptno = d.deptno
    where d.dname = 'SALES' or e.deptno is null

    清空数据表数据

     TRUNCATE TABLE    t_emp

  • 相关阅读:
    SPOJ NDIV
    SPOJ ETF
    SPOJ DIVSUM
    头文件--持续更新
    SPOJ FRQPRIME
    SPOJ FUNPROB
    SPOJ HAMSTER1
    观光
    最短路计数
    拯救大兵瑞恩
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/11322555.html
Copyright © 2011-2022 走看看