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

  • 相关阅读:
    hdu 2490 队列优化dp
    poj 1836 LIS变形
    hdu 3410 单调栈
    51nod 1437
    51nod 1215 单调栈/迭代
    51nod 1102 单调栈
    51nod 1272 思维/线段树
    51nod 1279 单调栈
    SpringMVC收藏
    今天接触枚举类型,感觉是C里面应该才有的东西
  • 原文地址:https://www.cnblogs.com/ericblog1992/p/11322555.html
Copyright © 2011-2022 走看看