CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

集合C=集合B-集合A 的查询怎样写?

楼主Bman(龙进)2005-09-23 15:03:53 在 MS-SQL Server / 基础类 提问

集合B结构如下所示:  
   
    T1         T2         T3  
   
  集合A结构如下所示:  
    t1         t2         t3  
   
  集合A与B的结构完全相同.  
  求   集合B-集合A  
  条件:当   t1t2=T1T2时   认为两记录相同.\  
   
  请求各位帮助 问题点数:20、回复次数:3Top

1 楼churchatp1(别看资料,看聊效!)回复于 2005-09-23 15:08:31 得分 15

select   *   from   b   where     not   exists(select   1   from   a   where   a.t1=b.t1   and   a.t2=b.t2)Top

2 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-09-23 15:08:39 得分 5

--try  
  select   *   from   B   a   where   not   exists   (select   1   from   表B   inner   join   表B   where   T1=a.T1   and   T2=a.T2)Top

3 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-09-23 15:13:42 得分 0

--我上面有点问题,  
  --测试环境  
   
  declare   @t1   table   (t1   int   ,t2   int   ,t3   int)  
  insert   into   @t1   select   1,2,3  
  union   all   select   1,2,4  
  union   all   select   1,3,4  
  union   all   select   2,3,4  
  union   all   select   3,3,4  
  union   all   select   5,3,4  
   
   
  declare   @t2   table   (t1   int   ,t2   int   ,t3   int)  
  insert   into   @t2   select   1,2,3  
  union   all   select   1,2,4  
   
  --查询  
  select   *   from   @t1   a     where     not   exists  
  (select   1   from   @t2   where   T1=a.T1   and   T2=a.T2)  
  --结果  
  t1                     t2                     t3                      
  -----------   -----------   -----------    
  1                       3                       4  
  2                       3                       4  
  3                       3                       4  
  5                       3                       4  
   
  (所影响的行数为   4   行)  
   
   
  Top

相关问题

  • ( winform ) 集合A是集合B的子集,C#什么算法可以求出 B-A ???
  • 如何将('a','b','c')这样的集合处理成结果集?
  • [急...]如何将数据库A中查询出来的数据集合保存为一个新的数据库B???
  • C/S OR B/S
  • b/s,c/s
  • C\S ====> B\S
  • C/S------------->B/S
  • 公司要把C/S 查询系统改为B/S 了。大家给点建议
  • 求一查询语句,有A,B,C三个数据表,现在以A表做目录,查询时同时在A,B,c三表中进行,但是内容可能在B表中,也可能在C表中,还有可能B,C
  • c#和SQL查询

关键词

  • 结构
  • 集合
  • union
  • where
  • not exists
  • select

得分解答快速导航

  • 帖主:Bman
  • churchatp1
  • zlp321002

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo