LoveUnix » DB2 & Informix » 集合操作符的疑问
让LU留住您的每

一天 让LU博客留住您的每一天
2007-7-21 18:41 eagle
集合操作符的疑问

except
except all
有什么区别,except是第一个查询的结果除去重复行,except all 是第一个查询中除去在第2个查询有匹配的数据行,用一个{0,1,2}和{0,1,3}的例子在db2中运行看了下结果,一样的,没看出什么差别来
还有interset 和interset all,在db2运行了一下,结果也是一样的,真有点糊涂了
照理说interset all的重复结果应该是还在的,返回结果应该是0,0,1,1才对吧?

2007-7-22 23:20 beginner-bj
用两个{0,1,2}和一个{0,1,3}的例子再看

2007-7-23 10:08 eagle
谢谢beginner-bj
不过intersect和intersect all的结果还是没看出区别来
按照定义来说,一个{0,1,2}和{0,1,3}结果就应该不同
intersect结果为0,1
而intersect all的结果为0,0,1,1,:sad

2007-7-23 12:57 beginner-bj
db2 => SELECT SALES_PERSON
db2 (cont.) => FROM SALES
db2 (cont.) => INTERSECT
db2 (cont.) => SELECT SALES_PERSON
db2 (cont.) => FROM SALES;

SALES_PERSON
---------------
GOUNOT
LEE
LUCCHESSI

  3 条记录已选择。

db2 => SELECT SALES_PERSON
db2 (cont.) => FROM SALES
db2 (cont.) => INTERSECT ALL
db2 (cont.) => SELECT SALES_PERSON
db2 (cont.) => FROM SALES;

SALES_PERSON
---------------
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
GOUNOT
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LEE
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI
LUCCHESSI

  41 条记录已选择。

db2 =>

2007-7-23 14:53 eagle
------------------------------ Commands Entered ------------------------------
select * from employee01;
------------------------------------------------------------------------------
select * from employee01

EMPNO  FIRSTNME   
------ ------------
000300 PHILIP      
000010 CHRISTINE   
000100 THEODORE   

  3 record(s) selected.


------------------------------ Commands Entered ------------------------------
select * from employee02;
------------------------------------------------------------------------------
select * from employee02

EMPNO  FIRSTNME   
------ ------------
000100 THEODORE   
000010 CHRISTINE   
000200 DAVID      

  3 record(s) selected.


------------------------------ Commands Entered ------------------------------
select * from employee01
intersect
select * from employee02;
------------------------------------------------------------------------------
select * from employee01 intersect select * from employee02

EMPNO  FIRSTNME   
------ ------------
000010 CHRISTINE   
000100 THEODORE   

  2 record(s) selected.


------------------------------ Commands Entered ------------------------------
select * from employee01
intersect all
select * from employee02;
------------------------------------------------------------------------------
select * from employee01 intersect all select * from employee02

EMPNO  FIRSTNME   
------ ------------
000010 CHRISTINE   
000100 THEODORE   

  2 record(s) selected.

2007-7-23 21:04 beginner-bj
db2 insert into employee01 select * from employee01
db2 insert into employee02 select * from employee02

2007-7-26 20:13 eagle
是我愚钝了,多谢beginner-bj

2007-7-27 17:08 fck
学习了!

页: [1]
查看完整版本: 集合操作符的疑问


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.