标题: 集合操作符的疑问
eagle
LU小天使
Rank: 3Rank: 3



UID 39336
精华 0
积分 320
帖子 484
活跃指数 26
LU金币 412 个
LU金条 0 个
阅读权限 20
注册 2006-1-10
 
发表于 2007-7-21 18:41  资料  个人空间  短消息  加为好友 
集合操作符的疑问

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

顶部
beginner-bj
版主
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15


UID 9471
精华 15
积分 1371
帖子 2360
活跃指数 186
LU金币 4355 个
LU金条 0 个
阅读权限 210
注册 2004-1-16
 
发表于 2007-7-22 23:20  资料  个人空间  短消息  加为好友 
用两个{0,1,2}和一个{0,1,3}的例子再看





我的博客:http://blog.chinaunix.net/index.php?blogId=739欢迎访问,并请多多批评指正。
顶部
eagle
LU小天使
Rank: 3Rank: 3



UID 39336
精华 0
积分 320
帖子 484
活跃指数 26
LU金币 412 个
LU金条 0 个
阅读权限 20
注册 2006-1-10
 
发表于 2007-7-23 10:08  资料  个人空间  短消息  加为好友 
谢谢beginner-bj
不过intersect和intersect all的结果还是没看出区别来
按照定义来说,一个{0,1,2}和{0,1,3}结果就应该不同
intersect结果为0,1
而intersect all的结果为0,0,1,1,

顶部
beginner-bj
版主
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15


UID 9471
精华 15
积分 1371
帖子 2360
活跃指数 186
LU金币 4355 个
LU金条 0 个
阅读权限 210
注册 2004-1-16
 
发表于 2007-7-23 12:57  资料  个人空间  短消息  加为好友 
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 =>





我的博客:http://blog.chinaunix.net/index.php?blogId=739欢迎访问,并请多多批评指正。
顶部
eagle
LU小天使
Rank: 3Rank: 3



UID 39336
精华 0
积分 320
帖子 484
活跃指数 26
LU金币 412 个
LU金条 0 个
阅读权限 20
注册 2006-1-10
 
发表于 2007-7-23 14:53  资料  个人空间  短消息  加为好友 
------------------------------ 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.

顶部
beginner-bj
版主
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15


UID 9471
精华 15
积分 1371
帖子 2360
活跃指数 186
LU金币 4355 个
LU金条 0 个
阅读权限 210
注册 2004-1-16
 
发表于 2007-7-23 21:04  资料  个人空间  短消息  加为好友 
db2 insert into employee01 select * from employee01
db2 insert into employee02 select * from employee02





我的博客:http://blog.chinaunix.net/index.php?blogId=739欢迎访问,并请多多批评指正。
顶部
eagle
LU小天使
Rank: 3Rank: 3



UID 39336
精华 0
积分 320
帖子 484
活跃指数 26
LU金币 412 个
LU金条 0 个
阅读权限 20
注册 2006-1-10
 
发表于 2007-7-26 20:13  资料  个人空间  短消息  加为好友 
是我愚钝了,多谢beginner-bj

顶部
fck
LU幼天使
Rank: 2



UID 87914
精华 0
积分 152
帖子 257
活跃指数 24
LU金币 275 个
LU金条 0 个
阅读权限 20
注册 2007-4-9
 
发表于 2007-7-27 17:08  资料  个人空间  短消息  加为好友 
学习了!

顶部
 



当前时区 GMT+8, 现在时间是 2008-7-9 17:15
乐悠LoveUnix论坛-京ICP备05005823号

Thanks to Discuz!  © 2001-2007    Power by LoveUnix.net
Processed in 0.069695 second(s), 6 queries , Gzip enabled

清除 Cookies - 联系我们 - 乐悠LoveUnix - Archiver - WAP