ORACLE 函数minus、intersect、union、union all 用法

来源:互联网 发布:js array split 编辑:程序博客网 时间:2024/05/22 15:30

1、oracle函数minus的作用简单来说就是“去同留异”
select ord.member_id
  from wltdata.wlt_order_info ord, wltdata.wlt_sub_order_info sub
 where ord.id_wlt_order_info = sub.wlt_order_info_id
   and ord.created_date >= sysdate - 2
   and rownum <= 10
   --order by 1
minus
select ord.member_id
  from wltdata.wlt_order_info ord, wltdata.wlt_sub_order_info sub
 where ord.id_wlt_order_info = sub.wlt_order_info_id
   and ord.created_date >= sysdate - 1
   and rownum = 10
   --order by 1
注意:1、放开 order by 报:ORA-00933: SQL 命令未正确结束;2、rownum 表示:伪列 ,每个表都有伪列。

2、oracle函数intersect的作用“取交集”用法同上。

3、union表示“并”,当用得时候,系统会自动将重复的元组去掉,如果想保留重复元组则就用union all

0 0