rownum函数、union并集、intersect交集、minus差集

来源:互联网 发布:乐视tv下载软件 编辑:程序博客网 时间:2024/06/04 17:59

rownum: 1、虚拟的,查询的时候才虚拟出来的。表中实际不存在。

2、一般不能直接写>,只能直接写<

3、通过子查询,可以使用>

select rownum,empno,ename from emp where rownum <5 order by empno;

select b ,empno ,ename from (select rownum b,emp.* from emp) a where a.b>5 and a.b<10;


union:并集,去重

select * from (select * from emp where sal<1000 union   select * from emp where sal <=2000)a order by empno;

union all:并集不去重

select * from (select * from emp where sal<1000 union all select * from emp where sal <=2000)a order by empno;

intersect:交集

select * from (select * from emp where sal<1000 intersect select * from emp where sal <=2000)a order by empno;

minus :差集

select * from (select * from emp where sal<2000 minus select * from emp where sal <=1000)a order by empno;

0 0
原创粉丝点击