当前位置: 代码迷 >> Oracle开发 >> oracle面试题,一个SQL话语,求解
  详细解决方案

oracle面试题,一个SQL话语,求解

热度:37   发布时间:2016-04-24 07:19:44.0
oracle面试题,一个SQL语句,求解
一些简单的sql语句,比如说 现在数据库中有10记录,要求你写一个语句保留第二条和第五条记录,将其他的记录全部删除。

------解决方案--------------------
SQL code
--举例如下SQL> delete emp  2      where not exists (select 1 from  3          (select rownum rn,empno from emp) t  4          where t.empno=emp.empno and t.rn in(2,5));已删除12行。SQL> select * from emp;     EMPNO ENAME                JOB                       MGR HIREDATE          ---------- -------------------- ------------------ ---------- --------------           SAL       COMM     DEPTNO                                                ---------- ---------- ----------                                                      7499 Allen                SALESMAN                 7698 20-2月 -81              1600        300         30                                                                                                                                      7654 Martin               SALESMAN                 7698 28-9月 -81              1250       1400         30                                                                                                                                SQL> rollback;回退已完成。
------解决方案--------------------
delete emp
where not exists (select 1 from
(select rownum rn,empno from emp) t
where t.empno=emp.empno and t.rn in(2,5));

  相关解决方案