Trafodion 操作结果集-并集、差集、交集

来源:互联网 发布:dos java 编辑:程序博客网 时间:2024/05/22 03:30

前几天社区有同学问到Trafodion是否支持操作结果集,答案是:支持!
Trafodion与很多其他关系型数据库一样,可以支持两个结果集的并集、差集、交集操作。语法如下,

//并集query-expr UNION [ALL] query-primary//交集query-expr INTERSECT query-primary//差集query-expr EXCEPT query-primary

下面我们一起在Trafodion中试验一下吧,假设有两个表t1,t2,内容如下

SQL>select * from t1;A-----------          1          2          3--- 3 row(s) selected.SQL>select * from t2;A-----------          1          2--- 2 row(s) selected.

1 并集-union [all],其中union具体排序去重的作用,而union all只是简单的合并

SQL>select a from t1 union select * from t2;A-----------          1          2          3--- 3 row(s) selected.SQL>select a from t1 union all select * from t2;A-----------          1          1          2          2          3--- 5 row(s) selected.

2 交集 –intersect

SQL>select a from t1 intersect select a from t2;A-----------          1          2--- 2 row(s) selected.

3 差集–except

SQL>select a from t1 except select a from t2;A-----------          3--- 1 row(s) selected.
阅读全文
1 0