a表是b表的子集,怎么得到b-a的记录,有这样的函数吗?求助!

alex5006 2003-08-19 05:16:47
a表是b表的子集,怎么得到b-a的记录,有这样的函数吗?最好一句sql实现,不要用游标,那样效率太低了。有什么好的解决方法吗?谢谢!!!
...全文
83 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
txlicenhe 2003-08-19
  • 打赏
  • 举报
回复
select * from b where 主键 not in (select 主键 from a)
hjb111 2003-08-19
  • 打赏
  • 举报
回复
是关系的差运算:
select * from b where not exists(select 1 from a where b.c1=a.c1 and b.c2=a.c2)

pengdali 2003-08-19
  • 打赏
  • 举报
回复
select * from b where 主键 not in (select 主键 from a)

或:

差:
c1-c2:

select * from t1 where not exists(select 1 from t2 where t1.c1=t2.c1 and t1.c2=t2.c2)

c2-c1:

select * from t2 where not exists(select 1 from t1 where t1.c1=t2.c1 and t1.c2=t2.c2)
happydreamer 2003-08-19
  • 打赏
  • 举报
回复

差:
c1-c2:

select * from t1 where not exists(select 1 from t2 where t1.c1=t2.c1 and t1.c2=t2.c2)

c2-c1:

select * from t2 where not exists(select 1 from t1 where t1.c1=t2.c1 and t1.c2=t2.c2)

CrazyFor 2003-08-19
  • 打赏
  • 举报
回复
select b.* from b left join a on b.字段1=a.字段1 and b.字段2=a.字段2....
where a.任一字段 is null


b.字段1=a.字段1 and b.字段2=a.字段2.... --这是确认是子集的条件

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧