一些SQL语言的基础问题?

zhuma 2003-08-26 10:31:07
希望解答以下问题
或提供相关论文或论坛
谢谢

1。SQL语言与一般算法语言的根本区别是什么?请解释高度非过程性、不需循环结构?
2。SQL语言与一般算法语言的相似性何在?
3。集合运算、关系代数以关系演算的描述如何映射到标准SQL?
4。SQL语句编写中是否有算法规则或推导规则?如有,包括哪些?
...全文
23 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
changechange 2003-08-29
  • 打赏
  • 举报
回复
关系运算:

并运算
select c1,c2 from t1
union all
select c1,c2 from t2

差:
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)

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


除:
create table #1(A char(1),B char(1),C char(1),D char(1))
insert #1 values('a','b','c','d')
insert #1 values('a','b','e','f')
insert #1 values('b','c','e','f')
insert #1 values('e','d','c','d')
insert #1 values('e','d','e','f')
insert #1 values('a','b','d','e')

create table #2 (A char(1),B char(1))
insert #2 values('c','d')
insert #2 values('e','f')

select a,b from #1 bb where exists(select 1 from (select distinct #1.a,#1.b,#2.a c,#2.b d from #1,#2) aa where aa.a=bb.a and aa.b=bb.b and aa.c=bb.c and aa.d=bb.d) group by a,b having count(*)>1





用left join来着差运算

create table #a(a int,b int)
create table #b(a int,b int)
insert #a values(1,1)
insert #a values(2,2)
insert #b values(1,1)
insert #b values(3,3)

#a-#b
select a.*
from #a a left join #b b on a.a=b.a and a.b=b.b
where b.a is null

#b-#a
select b.*
from #b b left join #a a on a.a=b.a and a.b=b.b
where a.a is null

or:
select b.*
from #a a right join #b b on a.a=b.a and a.b=b.b
where a.a is null
zhuma 2003-08-29
  • 打赏
  • 举报
回复
没人指点
呜呜

退而求其次
能不能给个学术讨论比较好的数据库论坛?
谢谢
ezhou 2003-08-29
  • 打赏
  • 举报
回复
关注。
zhuma 2003-08-26
  • 打赏
  • 举报
回复
其实我最近在作这方面的课题
想通过大家的意见
拓宽一下思路
并且
搜集一些资料

希望得到大家的进一步支持
谢谢
CrazyFor 2003-08-26
  • 打赏
  • 举报
回复
是啊,楼主还是一步一个脚印的走.:)
CrazyFor 2003-08-26
  • 打赏
  • 举报
回复
是啊,楼主还是一步一个脚印的走.:)
zjcxc 元老 2003-08-26
  • 打赏
  • 举报
回复
看书吧.
sdhdy 2003-08-26
  • 打赏
  • 举报
回复
呵呵,楼主问的问题比较大,实在不好回答,很不基础啊!
zjcxc 元老 2003-08-26
  • 打赏
  • 举报
回复
看书吧.
txlicenhe 2003-08-26
  • 打赏
  • 举报
回复
先用一下再说吧。
happydreamer 2003-08-26
  • 打赏
  • 举报
回复

关系运算:

并运算
select c1,c2 from t1
union all
select c1,c2 from t2

差:
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)

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


除:
create table #1(A char(1),B char(1),C char(1),D char(1))
insert #1 values('a','b','c','d')
insert #1 values('a','b','e','f')
insert #1 values('b','c','e','f')
insert #1 values('e','d','c','d')
insert #1 values('e','d','e','f')
insert #1 values('a','b','d','e')

create table #2 (A char(1),B char(1))
insert #2 values('c','d')
insert #2 values('e','f')

select a,b from #1 bb where exists(select 1 from (select distinct #1.a,#1.b,#2.a c,#2.b d from #1,#2) aa where aa.a=bb.a and aa.b=bb.b and aa.c=bb.c and aa.d=bb.d) group by a,b having count(*)>1





用left join来着差运算

create table #a(a int,b int)
create table #b(a int,b int)
insert #a values(1,1)
insert #a values(2,2)
insert #b values(1,1)
insert #b values(3,3)

#a-#b
select a.*
from #a a left join #b b on a.a=b.a and a.b=b.b
where b.a is null

#b-#a
select b.*
from #b b left join #a a on a.a=b.a and a.b=b.b
where a.a is null

or:
select b.*
from #a a right join #b b on a.a=b.a and a.b=b.b
where a.a is null
ZHANGWEI15 2003-08-26
  • 打赏
  • 举报
回复
资源 地址
Microsoft 产品支持服务 Web 站点 http://support.microsoft.com/directory
Microsoft Usenet news://msnews.microsoft.com/
Microsoft Windows® 硬件兼容性列表 http://www.microsoft.com/hcl
MSDN® http://msdn.microsoft.com
Meta Data Services(即以前的 Microsoft 知识库) http://msdn.microsoft.com
SQL Server 专业协会 http://www.sqlpass.org/
Microsoft SQL Server 开发人员中心 http://msdn.microsoft.com
SQL Server 杂志 http://www.sqlmag.com/
Microsoft SQL Server 技术支持 http://support.microsoft.com/support/sql
TechNet 站点 http://www.Microsoft.com/technet
Microsoft 辅助工具 Web 站点 http://www.microsoft.com/enable
Microsoft SQL Server Web 站点 http://www.microsoft.com/sql
Microsoft SQL Server Web 站点上的 English Query 页 http://www.microsoft.com/sql
Microsoft SQL Server Web 站点上的 Analysis Services 页 http://www.microsoft.com/sql
XML 开发人员中心 http://www.msdn.microsoft.com/xml/default.asp

34,575

社区成员

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

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