如何用SQL语句表示关系代数的除运算

badflyer 2003-01-12 03:16:50
关系
R: A B C D S: C D
1 2 3 4 3 4
7 8 5 6 5 6
7 8 3 4 4 2
1 2 5 6
1 2 4 2

R-S A B
1 2

怎样用sql写
...全文
156 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-01-12
  • 打赏
  • 举报
回复
declare @r table(a int,b int,c int,d int)
declare @s table(c int,d int)



insert @r values(1,2,3,4)
insert @r values(7,8,5,6)
insert @r values(7,8,3,4)
insert @r values(1,2,5,6)
insert @r values(1,2,4,2)

insert @s values(3,4)
insert @s values(5,6)
insert @s values(4,2)

select Distinct a,b from @r temp4 where not exists(
select * from (select a,b from (
select * from (select Distinct a,b from @r
) A,@s ) temp1 where not exists ( select 1 from @r temp2 where temp1.a=temp2.a and temp1.b=temp2.b and temp1.c=temp2.c and temp1.d=temp2.d))
temp3 where temp4.a=temp3.a and temp4.b=temp3.b
)

34,575

社区成员

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

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